|
Art
444 Lecture Notes
Flash MX 2004 Lecture
Notes
Basic Interactivity using Behaviors (see Chapter 12 of Ulrich book and Chapters 3 & 4 of Advanced MX 2004 book)
Note: we will be scripting buttons with more advanced techniques rather than using Flash's Behavior Panel. Please follow this tutorial when scripting button symbols.
- Accessing the Actions Panel: access the Action panel through Window> Development Panels. Actions or by clicking on the little arrow icon at the right side of the Properties panel.
- Frame Actions vs. Object Actions: (read inset on p. 449)
- Frame-based scripts are actions tied to a particular keyframe. The Stop frame action is an example of a frame-based script which stops the playback head on the frame it is placed on.
- Object-based scripts are attached to button and movie clip symbols as well as components. These actions usually require user interactivity to function (i.e. clicking a button).
- Note: It is easy to apply object actions to a frames and vice versa. In the actions panel, check to see that it reads the proper type of scripting at the upper left of the panel.
- IMPORTANT: Keep in mind that we will be mostly scripting with frame-based actions. More on this below.
- Creating a Dedicated Action Layer: you should keep your scripts organized on one layer dedicated to ActionScripts only. Name this layer "actions" and place it at either the top or bottom of your layer stack. See inset on p. 454 for more info.
- The Stop Action: the Stop action allows you to stop the playbackhead on a frame. To begin playback, the user must click a button, key, etc. that starts playback again. Add the stop(); actionby selecting a frame in timeline and place a blank keyframe (F7) if required - if you don't, Flash will find the first previous keyframe to attach it to. In Global Functions> Timeline Control dbl. click stop. The action will be added to the scrpting window.
- Using Frame Labels vs. Frame Numbers: GotoAndPlay and GotoAndStop can be scripted to go to a frame number or frame label. You should get in the habit of using frame labels only as they are unique name and can be easily found in movies with multiple scenes (i.e. every timeline has 1 - 100 or more numbered frames). Frame labels must be unique so they are easier to find.
- Note: this is especially important when we start working with multiple timeline control. ALWAYS USE FRAME LABELS.
- Adding a Frame Label: select the frame you wish to name and in the Frame Properties type in the unique name.
- Note: frame labels should not contain any special characters. Avoid spaces (or use an underscore) and keep them short and sweet. See inset on p. 442 for more info.
- ActionScript Syntax: Please note that ActionScripting is CASE SENSITIVE. Please read inset on p. 459 for more information.
- Naming Button Instances: because we be using an ActionScript layer to control all interactivity in our movie we must name each button or movie clip instance we plan to control with scripting. These names also need to be unique and should follow similar naming conventions as frame labels. Name the instance of your button symbol by selecting the object on the stage and typing in a name in the Properties panel.
- Note: Instance names are NOT the same as a symbols library name. You may use the symbol's name but only once if you are bringing multiple instances of the same symbol to the stage.
- Mouse Event Handlers: parameters include onPress, onRelease, onRelease Outside, onKeyPress (the button reacts to a specific key on the keyboard rather than the mouse), onRollOver, onRollOut, onDragOver, and onDragOut. Buttons may be set up to respond to multiple parameters. See pp. 467-472 for more info.
- gotoAndPlay and gotoAndStop: these two scripts allow you to jump to a different part of a movie's timeline and either play from or stop at the specified frame. Both of these scripts may be used for frame and object control. Global Functions> Timeline Control> gotoAndPlay (or stop) and type theframe label name within the parentheses provided using DOUBLE QUOTES.
- Example: gotoAndPlay("intro");
- Loading
New Files: Flash allows you to link to another
web site with the Get url script from Browser/Network list. Type the url (again using double quotes) within the parentheses beginning with http://. A target such as _blank (opens the url in a new window) may be specified as well which is separated with a comma.
- Example: getURL("http://www.yahoo.com", "_blank" );
- Editing the Actions List: retype, select & delete an action from the list but be careful that you are not deleted necessary syntax symbols.
Putting it all together:
Below are two examples of scripting you will be using in the Flash animation assignment (both required). ActionScripts reside on a frame of a layer in your main timeline called "Actions". After selecting the frame of your action layer, click the arrow icon in the Properties window. The ActionScripting window will appear.
Note: These scripts must be used in conjunction with a stop(); action and should be placed at the stop of your script list. Basic button "goto" script:
button_name.onPress = function() {
____gotoAndPlay("credits");
}
The above script controls a button symbol on the stage with an instance name of button_name (replace with your button's instance name) and don't forget the dot (.) which separates the instance from the event onPress. Clicking the button will move the playhead to the frame label named credits. Note "credits" can be a frame label in a different scene of your movie.
A new script should be typed below the closing bracket.
Variation: use onRelease instead of onPress. Use gotoAndStop instead of play.
Basic button using getUrl script:
button_name.onPress = function() {
____getURL("http://www.yahoo.com", "_blank" );
}
The above script controls a button symbol on the stage with an instance name of button_name (replace with your button's instance name) and don't forget the dot (.) which separates the instance from the event onPress. Clicking the button will open a blank browser window and will link you to the Yahoo homepage.
The script window can have multiple scripts associated with one frame of your timeline controlling several different symbol instances. Be sure to place each new script under the previous script's closing bracket. Placing button scripts on the first frame of your timeline will enable the button's functionality to be availble from that frame on.
|