Coder Profile - Show off your skills, get a coder profile.
 
 
 
Actionscript Events
Programming
Events are the heart of Actionscript. Without them, you are pretty much completly rendered helpless when creating, pretty much anything, in Flash. Events are basically different actions that if performed, follow through with a block of code.

For example:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. function onMouseDown() {
  2.         trace("Mouse Pressed");
  3. }
What this code does is it places the mouseDown() event into a function and traces (outputs) the text "Mouse Pressed" when the user clicks the mouse.

There are three different ways to use events... On movieclips, on buttons (now depreciated since Actionscript 3.0 and Adobe Flash CS3) and on frames.

When placing events on buttons, the syntax is quite simple:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. on (event) {
  2.         //code
  3. }
Example:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. on (press) {
  2.         trace("Mouse Pressed");
  3. }
The same method goes for the same with movieclips.


Placing events on frames is a little bit different... You can access them in a few ways:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. function onMouseDown() {
  2.         //code
  3. }
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. onMouseDown = function() {
  2.         //code
  3. }
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. myMC.onMouseDown = function() {
  2.         //code
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. onMouseDown = myFunction;
  2.  
  3. function myFunction() {
  4.         //code
  5. }
The first code block inserts the event into a function and follows through with the code when it has happened. Remember, all events (not placed on buttons or mc's) must be placed on in a function syntax, or else it won't work.

The next code block is the same as the first, but with different syntax.

The third places the event directly on a movieclip, so it has direct access the that movieclip (the syntax also applies to that when on a movieclip, so you still need to call _root when reffering to other objects).

The final one places a the event on a seperatly declared function, so you can switch the functions around when you want to.


Finally, here's a list of every the most used events and what they do:

onMouseDown- When the mouse button is clicked

onMouseUp- When the mouse button is released

onMouseMove- When the user moves the mouse

onMouseWheel- When the mouse wheel is used

onLoad- When the frame/movieclip/button first loads

onEnterFrame- Runs the function the number of your fps per second

onPress- When a button or movieclip is pressed

onRelease- When a button or movieclip is released

onReleaseOutside- When a button or movieclip is released outside of its bounding box

onRollOver- When a button or movieclip has the mouse moved over it

onRollOut- When a button or movieclip has the mouse moved off of it

onKeyDown- When the user presses any key on their keyboard

onKeyUp- When the user releases any key on their keyboard

onSetFocus- When an object recieves focus

onKillFocus- When an object loses focus


Posted By mikeMarek
Please login to rate coding articles.

Click here to register a free account with us.
Comments
Please login to post comments.
 
Anto     Posted 2.85 Years Ago
 
 
I believe this is great for starters, good job!
Page 1 of 1
More Articles By This Author
[PHP] Create A Unique Page Hits Counter
Actionscript Events
Actionscript API
if/else, switch/case and ?/: Statements In Actionscript 2.0
Recently Posted "Programming" Articles
thetrojan01's brainfuck tutorial - from the beginning to the interpreter.
My Experiences So Far with Languages
Selecting Your First Programming Language
[PHP] - Lets kill the complex IF
Basic PortScanner in VB6.0
N-Queens-Series Part I (Only the fittest survive)
Currying in JavaScript: Fun for the Whole Family!
[PHP] Create A Unique Page Hits Counter
Actionscript Events
Actionscript API
Recently Rated "Programming" Articles
thetrojan01's brainfuck tutorial - from the beginning to the interpreter.
[PHP] - Lets kill the complex IF
Actionscript API
Actionscript Events
My Experiences So Far with Languages
Selecting Your First Programming Language
Vectors in C++
[C++] Templates
Quick Threading Tutorial - C++
Intorduction to memoization.
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Hardware (1)
Internet & Web Sites (3)
Life In General (2)
Networking (1)
Operating Systems (4)
Other (2)
Programming (46)
Security (8)
Software Development (5)
Web Development (14)
search Search Inside
Programming
 
 
Latest News About Coder Profile
Coder Profile Poll
Which sounds better on your coder profiles, and makes more sense to you (think twitter, facebook, etc)?

Followers / Following
Fans / Following
Fans / Fan Of


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.20 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved