is it possible to get flash to play x amount of frames before completing the gotoAndPlay from a button click.

Dani AI

Generated

's timeline-based approach is a solid, pragmatic AS2-era solution: set a target on click, let the exit animation play, then perform the jump when the timeline reaches the resume point. For maintainability and fewer globals, consider an event-driven or listener-based pattern instead.

If you're on ActionScript 3, a simple, clearer pattern is to start the transition, count frames with an Enter Frame listener, and then perform the navigation when the desired number of frames have passed. Example:

var framesToPlay:int = 12;
navButton.addEventListener(MouseEvent.CLICK, onNavClick);

function onNavClick(e:MouseEvent):void {
    navButton.mouseEnabled = false;
    var framesPlayed:int = 0;
    this.addEventListener(Event.ENTER_FRAME, onCount);
    play();

    function onCount(ev:Event):void {
        framesPlayed++;
        if (framesPlayed >= framesToPlay) {
            removeEventListener(Event.ENTER_FRAME, onCount);
            gotoAndPlay("targetLabel");
        }
    }
}

Troubleshooting and best practices:

  • Frame counting depends on the SWF frame rate; for timing-sensitive transitions use a Timer or signal the end of the animation from the last frame instead of relying purely on frame counts.
  • Disable navigation controls during the transition to avoid double firings. Re-enable after the jump or when the new page is ready.
  • Verify that your label exists before jumping (avoid runtime errors). In AS3, prefer calling methods on the document/root via typed references rather than scattering globals.
  • For larger projects, separate visual transition clips from navigation logic. Let the transition dispatch a completion event and let a central navigation handler respond.

This keeps the UI predictable, reduces hidden state, and scales better than many timeline-only hacks.

yes it is possible and here is how it is done.

firstly in frame one of the timeline a variable needs to be set. i set this as

var frame : String;

once this has been done you next need to add the

stop();

in the frame where you want the play head to pause. As mine then had the animation after the pause for the page exit, you will need to add this code to frame at the end of the page.

stop();
if(_level0.frame != undefined){
_level0.gotoAndPlay(_level0.frame); // or gotoAndStop(_level0.frame_to_goto)... If you want it to stop on that frame...
}else{
trace("An error as occured!");
}

this section of the code is looking for a variable to be sent to it from the button being clicked on. The code to get the variable to be sent will obviously go on to the button.

the code which goes on the button is this

on(release){
// set the variable...
_level0.frame = "_page1"; // assuming that's the frame's label...
//play the timeline from the next frame to frame 25...
play();
}

this will then pause where you want it to pause and when a button is pressed it will play the animation for the page exit then take the user to the page the have requested depending on which button is pressed.

just to clear things up a bit for any novice flashers i had a layer for the actions where all the code script went to make the play head stop and play. also i hab a layer called labels which gave the variables being sent to the script a place to go to.

where you see in the script "_page1" this are the labels for the beginning of each page.

if anyone needs help with this or i have just done a bad job of trying to explain what i have done pm me and i will help as much as i can.

commented: Good job Kevin +10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.