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:
function onMouseDown() { trace("Mouse Pressed"); }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
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:
on (event) { //code }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
Example:
on (press) { trace("Mouse Pressed"); }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
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:
function onMouseDown() { //code }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
onMouseDown = function() { //code }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
myMC.onMouseDown = function() { //code
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
onMouseDown = myFunction; function myFunction() { //code }
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
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