Groups | Blog | Home
all groups > flash (macromedia) > july 2005 >

flash (macromedia) : Action to Replay Movie


David Stiller
7/7/2005 7:43:48 PM
Comp. 792,

[quoted text, click to view]

Two ways to do that. If your movie only has this one button, the
quickest, easiest way to handle it is to select the button itself, then open
the Actions panel. In the Actions panel, assign an action to the event
handler for this button. The on() handler will do this. Buttons have an on
(press), on (release), and other events. on (release) makes the mose sense.

In the Actions panel with that button selected, type ...

on (release) {
gotoAndPlay(1);
}

The other way to do this is to assign your event handler to your button
from a frame script rather than code attached directly to the button. For
the second approach, you must give your button an instance name, so that
code will know whom it is addressing.

Select your button and look in the Properties inspector. You'll see
where you can provide the instance name. Let's say you call it "replay"
(though you can call it whatever you like). Once the instance name is
provided, create a new layer called "scripts" (call it what you like) and
put a keyframe in the same frame as your button. In the keyframe on your
scripts layer, type ...

replay.onRelease = function() {
gotoAndPlay(1);
}

Remember, don't do both. Pick one approach or the other. I prefer the
second approach, because it allows me to put all my code into one place (the
scripts layer), rather than attached separately to countless buttons -- but
the road you take is up to you. :)

Look up gotoAndPlay() in the ActionScript Language Reference (F1 key)
for complete details and examples.


David
stiller (at) quip (dot) net
Tackling the ActionScript Language Reference
http://www.quip.net/tutorials/

Comp. 792
7/7/2005 9:51:36 PM
I've placed a "stop"action at the end of my movie. I also placed a Play Movie
button in the last frame of my movie. How do I add an action to the Replay
Movie button so when the user clicks the button the movie replays?
Comp. 792
7/8/2005 12:00:00 AM
Thanks David, I will give it a try.

AddThis Social Bookmark Button