|
Home
>> Production
>> Flash and ActionScript >>
ActionScript Part V
ActionScript: Controlling a Timeline with instance
names
When you want to use Flash for interactivity, the
ability to press buttons or drag images on the screen to trigger
new events (such as: jumping to another section of a Flash Web
site, or the ability to turn off music by pressing a button, or
to tell a movie clip symbol to stop playing) then you will need
to understand how you can use actions in one timeline to control
the actions or behavior of another timeline.
Example: Where's
Goldy:[view
swf] . [download
fla]
In this example, there are multiple instances of
the same mc (movieclip) symbol of a swimming goldfish on the stage
in the main timeline. By giving one mc a unique instance name,
we can communicate directly with that one instance (and not all
of the other instances of the mc that are also on the stage).

We can right-click on any one of these fish and
choose Edit in Place to see the timeline of the Fish Movie Clip
symbol.
Notice how this timeline is set up. The playhead
runs through the timeline, hits an action on frame 95 which sends
it back to frame 1 and it continues looping, never to reach frame
96 or the stopgoldy label on frame 115.

But by using the Tell Target command in Actionscript,
we can click a button on the main timeline (which in Actionscript
is called _root) to "talk" to our one instance of this
symbol (the one we named goldy). We can say: "when I press
this button, I want to tell that one instance of the symbol to
jump out of the loop and go the frame labeled "stopgoldy".
Pressing the button Where's Goldy tells the mc named
"goldy" to go the label "stopgoldy" where
it will take one final stroke and then stop.
To program the Where's Goldy button:
1. Right-click the button on the main timeline and
select Actions to bring up the action editor.
2. Double-click the Tell Target action in the menu
under Basic Actions. It will automatically add the code on (release)
because it knows you are putting an action on a button as opposed
to a movieclip.
[Note: You can select the on release part of the
code so that you can edit whether you want this to happen on roll
over, press or roll out instead of on release. ]
3. Click inside the text field labeled Target at
the bottom of the editor, and notice that the little navigator
icon has changed from grey to blue. Click this icon to select
the named instance you want to target.

4. In the Target editor, you can specify an absolute
path or a relative path.
|

|
The absolute path is:
_root.goldy
|
 |
The relative path is:
goldy
|
What's the difference?
Absolute: If we wanted
to give directions to the instance from the main timeline, we
would say:
start at the root timeline, the main timeline (Scene
1). From here we should see a movie clip symbol with the instance
name "goldy".
ActionScript uses dot syntax (instead of slashes
when we link by pointing to the path of another file using HTML)
in its path names. So using an absolute path (starting from the
root) the target would be:
_root.goldy
Relative: Whereas
an absolute path finds the instance name from the main timeline,
a relative path gives directions from the timeline where the action
is located. In this case, the tell target action is attached to
a button symbol which is on the same timeline as the instance
named goldy (both are on the main timeline). Since they're both
in the same timeline (like in HTML, as if they're in the same
folder or directory) then we only need to say "goldy"
in order to target the mc. We don't have to say go to the root
timeline first, because we're already there.
The relative path (starting from the timeline _root
where the tell target action is located) would be:
goldy
5. In this case, it's easier to just say goldy,
so select the relative mode in the target path editor and then
click OK.
6. Now that we have identified and pointed to the
timeline we want to target, then we have to tell it what we want
it to do. Here, we want it to go to and play the frame label "stopgoldy",
which it would never have been able to get to because of the loop
we set up in that movie clip timeline.
Double click the Go To button in the menu under
Basic Actions, and then fill in the properties at the bottom.

To program the Swim Goldy Button:
7. To tell the goldy timeline to start playing again,
we assign another Tell Target action, this time to the button
symbol "Swim Goldy!". When we click this button, we
want the goldy timeline to go to the beginning and resume the
loop.
That's it! Close the Actions editor, go back to
the main root timeline, scene 1, and test your move.
Summary:
By giving one instance of a movie clip symbol it's
own name, you can "target" that timeline. (And which
does not effect the behavior of any other instances of this movieclip
you might also have on the stage.) By targetting it, you can change
it's size, visibility, rotation, color, or tell it to go to a
specific label in that mc instance's timeline.
Read more about this in your book:
More about Targetting other movies: pages 287-295
Read about naming an instance of a movie clip symbol
in Franklin and Patton, top of page 186 "Movie Clip behavior
option" Then read about targetting "Tell Target"
pages 312-314.
Then read the more in depth section on targetting
multiple timelines pages 358 to the top of 367 (especially 360-61)
|