View comments | RSS feed

gotoAndPlay()

Availability

Flash 2.

Usage

gotoAndPlay([scene:String,] frame:Object) : Void

Parameters

scene An optional string specifying the name of the scene to which the playhead is sent.

frame A number representing the frame number, or a string representing the label of the frame, to which the playhead is sent.

Returns

Nothing.

Description

Function; sends the playhead to the specified frame in a scene and plays from that frame. If no scene is specified, the playhead goes to the specified frame in the current scene.

You can use the scene parameter only on the root Timeline, not within Timelines for movie clips or other objects in the document.

Example

In the following example, a document has two scenes: sceneOne and sceneTwo. Scene one contains a frame label on Frame 10 called newFrame and two buttons, myBtn_btn and myOtherBtn_btn. This ActionScript is placed on Frame 1, Scene 1 of the main Timeline.

stop();
myBtn_btn.onRelease = function(){
   gotoAndPlay("newFrame");
};
myOtherBtn_btn.onRelease = function(){
   gotoAndPlay("sceneTwo", 1);
};

When the user clicks the buttons, the playhead moves to the specified location and continues playing.

See also

MovieClip.gotoAndPlay(), play(), nextFrame(), prevFrame()

Comments


helentriolo said on Oct 26, 2004 at 9:01 AM :
If you want to use gotoAndPlay to go to a particular scene, make sure
you give the first frame of that scene a frame label (one that matches the
name of the scene if you don't want to add confusion). Eg, to play a
scene named "part2", click on frame 1 of any layer in the part2 scene,
and type part2 into the frame label box in the Properties panel. Then
you can use this code on a button in another scene to go to that scene:

on (release) {
gotoAndPlay("part2");
}

(I couldn't get the gotoAndPlay to work for a scene any other way).
No screen name said on Nov 18, 2004 at 2:04 PM :
I couldn't get gotoAndPlay to go to a particular scene for any scene name or frame label; only gotoAndStop would work.
Emotinator said on Jan 11, 2005 at 2:10 PM :
if you want the scene to go to a variable label it doesn't work with just a:
gotoAndPlay(varName);

but it does work with
_root.gotoAndPlay(varName);

must be something buggy with the code, but that's a work around.
No screen name said on Jan 18, 2005 at 11:38 PM :
what if i am in a movieclip and i want to make a button to goto a specified frame in another scence , how i can do it
orbi2004 said on May 23, 2005 at 2:07 PM :
What if i have a scene with a movie clip in it and i want ot gotoandplay() from a named frame in a nested clip EG

scene1
movie1
framez
movie2
framex

so the play head gets to movie1.framez and then i want to stop() it and start movie2.framex
What is that syntax I cant find it anywhere

this is what i tried

gotoAndPlay("_root.mcSen001.movie1.movie2", framex);
stop()

but it wont work is this how you refer to a frame in a movie, if so why wont it work?
Thanks

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001363.html