GDT 260 Animation for the Web: Winter 2002
2.28.2002
Intelligent Actions
Remember:
- ActionScript is event driven
- Plan ahead - know what you want your movie to do
Communication Between Symbols
With actionscript, symbols can tell each other what to do with the tellTarget action.
The teller (button, movie clip, or main timeline) controls the target (movie clip only)
In order to easily use tellTarget, you must name the instance of the movie clip you wish to control on the Instance panel. This is called instantiation.
Remember that all instances of a symbol are tied to the symbol in the library. When modifying the symbol in the library, changes apply to all instances of that symbol. But, we can change the attributes of instances, including:
- Color
- Brightness
- Alpha
- Position
- Size
- Which frame is playing
Variables and Conditional Structures
Variables
Variables are simply named storage units that hold some value, sort of a cubbyhole with a name on it. The value of variables can stay constant, or it can change.
There are two types of variables in Flash:
- Literal (strings) - generally text. Flash takes this a face value. Strings are always quoted. Example 1:
name = "Chris";Example 2:eyeColor = "blue"; - Expressions - numbers and equations. Flash needs to calculate the final value for an expression. Always unquoted. Example 1:
dollars = 10;Example 2:dollars = dollars + 10;
Conditional Statements
Allows Flash to make a choice. If some condition is true, do this. If it's not true, don't do anything.
Example: If my name="Chris", say "Hi Chris", or else, say "Hi there"
Generally, if statements evaluate whether or not a variable meets a certain condition. If it does, we tell it to do one thing. If it doesn't, we have the option of telling it to do something else, or nothing at all.
if (name=="Chris") {
say("Hi Chris");
} else {
say("Hi there");
}
Exercises
- Make a movie that counts and constantly displays the number of times a button has been clicked
- You'll need to create a dynamic text field for this to work. Use the text tool, go to the Text Options palette, and select "Dynamic Text" from the dropdown menu. Give the text field a variable name like "clicks"
- If you want a 0 to display in your text field before the button has been clicked, you'll need to set your variable to 0 in frame 1, and stop the timeline from playing.
- Modify that movie to only update the counter display when a second button is pressed (Hint: You'll need two variables)