gotoAndStop( ) Global Function

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
gotoAndStop( ) Global Function Flash 2

move the playhead to a given frame, and stop the current clip or movie
gotoAndStop(frameNumber) gotoAndStop(frameLabel) gotoAndStop(scene, frameNumber) gotoAndStop(scene, frameLabel)

Arguments

frameNumber

A positive integer indicating the number of the frame to which the playhead of the current timeline should jump. If frameNumber is less than 1 or greater than the number of frames in the timeline, the playhead is sent to either the first or last frame, respectively.

frameLabel

A string indicating the label of the frame to which the playhead of the current timeline should jump. If frameLabel is not found, the playhead is sent to the first frame of the current scene.

scene

An optional string indicating the name of the scene that contains the specified frameNumber or frameLabel. If not supplied, the current scene is assumed.

Description

When invoked without a scene argument, gotoAndStop( ) sends the playhead of the current timeline to the frame specified by either the frameNumber or frameLabel argument. The "current timeline" is the movie or movie clip from which the gotoAndStop( ) function is invoked. The playhead will stop at the target frame; it will not advance automatically after arriving at the target frame.

If two arguments are specified in the gotoAndStop( ) function call, the first argument is assumed to be the scene. If only one argument is specified, it is treated as a frameNumber or frameLabel, and the current scene is assumed.

When invoked with a scene argument, gotoAndStop( ) moves the playhead to the frame number or label in the specified scene and then halts playback. If a scene argument is used, the gotoAndStop( ) function must be invoked from the _root timeline; otherwise, the operation fails silently and the playhead is not sent to the destination frame.

The global gotoAndStop( ) function affects only the current timeline. The frames or state of other movie clips within the current timeline are not affected. To move the playhead of other movie clips, you must issue a separate gotoAndStop( ) command for each movie clip. To apply the gotoAndStop( ) function to a clip besides the current movie clip, use the movie clip method form, MovieClip.gotoAndStop( ).

Bugs

In Flash Player 5 and Flash Player 6, gotoAndStop( ) does not work when used in an onClipEvent( ) handler with a string literal for frameLabel.

In Flash Player 4 and later, when a nonliteral frameLabel argument is specified in any scene other than the first, the playhead jumps to the specified label plus the total number of frames in all scenes before the current scene.

To work around both bugs, use the movie clip variation of gotoAndStop( ) and specify this to indicate the current clip, as in this.gotoAndStop("myLabel"), rather than gotoAndStop("myLabel").

Example

// Go to frame 5 of the current timeline, and stop there gotoAndStop(5); // Go to frame 20 of the introSequence scene, and stop there gotoAndStop("introSequence", 20); // Go to frame "hello" of the introSequence scene, and stop there gotoAndStop("introSequence", "hello") // Caution! This goes to the frame labeled "introSequence" in the current scene gotoAndStop("introSequence") // This goes to frame 1 of the introSequence scene gotoAndStop("introSequence", 1)

Reader Exercise: Write a custom function, gotoDeltaAndStop( ), that allows the caller to specify a relative frame number, including a negative one. For example, gotoDeltaAndStop(-5) would jump backward by 5 frames. (Hint: You'll need the MovieClip._currentframe property.) Remember to add any special code to handle the end conditions (i.e., when a relative frame number would cause it to jump beyond the beginning or end of the current timeline).

See Also

gotoAndPlay( ), MovieClip.gotoAndStop( ), play( ), stop( )



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net