Wuffa!
We've seen where ACTIONS and PROPERTIES can be attached to a movie clip or other symbol with Actionscript. Now, let's attach an EVENT to the clip, and use this to define a FUNCTION.
The events we're used to in Actionscript look like this when they're attached to a button:
on (release) {
//something happens;
}
where "release" is the event, and the next line determines what happens.
When you attach an EVENT to a clip, you drop the parentheses, and capitalize the first letter of the event:
_root.clip01_mc.onEnterFrame = (and this is followed by a function declaration, below . . . .) **
A FUNCTION is a bunch of Actionscript - - from several lines to hundreds of lines, including functions within functions - - that does something, that functions in some way. The syntax of a FUNCTION is:
1) DEFINE the function - - state what it does. This usually goes on the FIRST FRAME, FIRST LAYER, MAIN STAGE ("Scene 1").
2) CALL the function - - a button somewhere addresses the function so it can execute what it needs to do.
Here's a simple function that makes a movie clip go to a particular frame. It would be put on the FIRST FRAME, FIRST LAYER, MAIN STAGE ("Scene 1"):
moveThatThing = function(){
_root.clip01_mc.gotoAndStop("beginning");
}
A button on the main stage would have this script:
on (release){
_root.moveThatThing();
}
Not a big deal, really, but what if you have 14 different movieclips that you want to send to 14 different labels? For that, you build a FUNCTION with PARAMETERS. A PARAMETER is a placeholder for a variable - for anything that can change.
Parameters are stated in the PARENTHESIS of the function, and then their relationship to the FUNCTION is further defined as we define the function. The parameters are PLACEHOLDERS, remember. I name them all with "which___" because it forces me to define their role in the function:
moveThatThing = function(whichClip, whichLabel){
whichClip.gotoAndStop(whichLabel);
}
When the function is CALLED by the button, the PARAMETERS go into the parenthesis of the call, and they are PLUGGED IN to the function. That way, you write a function once, and you apply it to as many like-objects as you need, just by changing the parameters:
on (release){
_root.moveThatThing(_root.clip01_mc, "beginning");
}
OK, that's how FUNCTIONS, PARAMETERS, EVENTS, PROPERTIES, and VARIABLES work together. Know what each one does, and how they work!
Everything you've done in this tutorial will change certain properties or other elements in a Flash site INSTANTLY. But, you may want these changes to take place gradually (i.e., as animations), so go to the next part of the tutorial to find out how to do that!
Comments (0)
You don't have permission to comment on this page.