GDT 260 Animation for the Web: Winter 2003
Notes & Handouts February 20
Actions & Interactions
Interactivity: the ability of the movie to respond to user actions. In Flash, all interactivity is accomplished by ActionScript.
Events and Event Handlers
Flash and ActionScript are event-driven: something needs to happen, and Flash will handle that event and execute an action.
- Event
- Something that happens, i.e., a mouse click, or the movie enters a certain frame, or the user hits a certain key.
- Event Handler
- The movie’s response to an event, in the form of
on (event) { do some stuff }Basically a set of instructions to watch for an event and then do something when that event occurs.
The most straightforward event-sensitive element is a button, which already has different visual states that respond to events. By adding an event handler to a button, the button will watch for the specified event, and follow the instructions within the event handler when it happens.
Buttons aren’t inherently interactive—they need actionScript to tell them what to do.
ActionScript allows non-linear timeline—decision-making & choice by user
Interactive Buttons
Button Events
- Press a mouse click, the moment when the button is initially down
- Release when the mouse button is released
- Release Outside when the mouse button is released after the user moves the mouse off the button
- Roll Over, Roll Out when the mouse moves over a button, and when it moves off of the button
Actions attached to buttons on the stage are attached to that instance only, not to the item in the library
Animated Buttons
Add an animated movie clip to either Over or Down state of button timeline
Attaching Sounds to Buttons
- Add sound to library (File > Import or drag from another library)
- In button symbol add new layer
- Add a keyframe at either over or down, depending when you want the sound to happen
- Select the keyframe and select the sound from the Sound dropdown in the Properties Panel
Timeline vs Instances
ActionScript can be attached to a keyframe within the timeline or to an instance of a symbols on the stage
- ActionScript attached to a keyframe executes when the playhead moves into that frame
- ActionScript attached to an instance of a button reacts to user-initiated events—clicks & mouseovers
- The actionscript editor window title will change to indicate whether you're adding actions to a frame or to an instance of a symbol.
Event Handler Statement
on (event) {
actionscript telling movie what to do
}
Anything between curly braces is executed in response to the event in the order that it appears. Actions that you want to execute must appear between curly braces! If they don't appear within the curly braces, select the line and use the arrow tools in the actionscript editor to move the line inside them.
Frame Labels
Allow actions like gotoAndPlay() to use a frame name rather than a hard-coded frame number, so that you can change the number of frames in your movie without affecting the actions.
To add a label to a frame:
- Add a keyframe or select an existing one
- In the Properties Panel, type in a label name into the text field on the left that says <Frame Label>