Clip Events
Now, I want you to take a look at something:
onClipEvent(type){ }
What does this look like? Did you think “function?” Well if you did, you are right. It looks like a function without function in front of it. Where it says “type,” this is where you put the type of event (remember that an event is what triggers an action). In fact, you can see that inside the parenthesis is where arguments go(remember that changing an argument is like switching actors out).
So, a clip event is function with an argument. The function and the arguments that can go into the function are pre-defined. Check out these other possible Clip Events:
onClipEvent(load){ }
onClipEvent(unload){ }
onClipEvent(enterFrame){ }
onClipEvent(mouseDown){ }
onClipEvent(mouseUp){ }
onClipEvent(mouseMove){ }
onClipEvent (keyDown) { }
onClipEvent (keyUp) { }
onClipEvent (data) { }
Macromedia FlashMX 2004
----------------------------------------
A movieEvent is a trigger called an event. When the event occurs, the statements following it within curly braces ({}) are executed. Any of the following values can be specified for the movieEvent parameter:
load The action is initiated as soon as the movie clip is instantiated and appears in the Timeline.
unload The action is initiated in the first frame after the movie clip is removed from the Timeline. The actions associated with the Unload movie clip event are processed before any actions are attached to the affected frame.
enterFrame The action is triggered continually at the frame rate of the movie clip. The actions associated with the enterFrame clip event are processed before any frame actions that are attached to the affected frames.
mouseMove The action is initiated every time the mouse is moved. Use the _xmouse and _ymouse properties to determine the current mouse position.
mouseDown The action is initiated when the left mouse button is pressed.
mouseUp The action is initiated when the left mouse button is released.
keyDown The action is initiated when a key is pressed. Use Key.getCode() to retrieve information about the last key pressed.
keyUp The action is initiated when a key is released. Use the Key.getCode() method to retrieve information about the last key pressed.
data The action is initiated when data is received in a loadVariables() or loadMovie() action. When specified with a loadVariables() action, the data event occurs only once, when the last variable is loaded. When specified with a loadMovie() action, the data event occurs repeatedly, as each section of data is retrieved.
--------------------------------------
So, these pre-made functions are made specifically for Movie Clips. A Movie Clip is just what it sounds like. A movie clip is like a piece of footage for the movie. All of the above pre-made functions have to do with Movie Clips.
Here is a simple blank example:
onClipEvent (keyDown)
{
if()== Key.RIGHT{}
else if()==Key.LEFT{}
}
What happens is that when a certain key is pressed down, the stuff inside the braces happens to the movie clip. We could have made our own function that did this, but we would probably have to make the function and then add an event listener to it. Clip Events make it easy to trigger Movie Clips.
So, this is read:
If…is Key.Right do something. Otherwise if… is Key.LEFT do something else.
Here is a filled in example:
onClipEvent (keyDown)
{
if(Key.getCode())== Key.RIGHT
{this._parent.nextFrame(); }
else if((Key.getCode() )==Key.LEFT
{this._parent.prevFrame(); }
}
So, this is read:
When a key is pressed, if the key code is “right key” this movie clip goes to the next frame. Otherwise, if the key code is “left key”, this movie clip goes to a previous frame. Notice that “nextFrame” and “prevFrame” are methods.
Look at this other example:
onClipEvent (load)
{
this.createTextField("coords_txt", this.getNextHighestDepth(), 0, 0, 100, 22);
coords_txt.autoSize = true;
coords_txt.selectable = false;
}
onClipEvent (mouseMove)
{
coords_txt.text = "X:"+_root._xmouse+",Y:"+_root._ymouse;
}
So, when this particular movie clip loads up, this movie clip creates a text field, gets the next highest depth, autosizes corrds_txt, and makes it un-selectable.
Also, when the mouse moves, coords_txt.text is changed to X: plus the mouse’s x position and Y: plus the mouses y position. Don’t be afraid of this, I don’t know exactly how they came up with this stuff either, but let us break it down according to what we know.
The “creatTextField()…22)” looks like a variable with an array, one of the things in the array being a variable with a property. It certainly looks like a method too:
“(.createTextField();)”
Also, the “autoSize…” looks like a property, so does “selectable….” As a matter of fact, “selectable” and “autoSize” could be variables that haven‘t been given roles; something like:
var autoSize: Boolean;
var selectable: Boolean;
The cords _txt is a text field of course, and it seems that “.text” is a property of it. “X:…” looks like some math stuff. It seems that the text of the text field, cords_txt, is being changed to X: + mouse X position + Y: + Y mouse position. So the the text field might display:
X:200
Y:300
(200 and 300 being in pixels)
Resources for some information listed can be found in the Resource.pdf file.