Skip to main content
January 15, 2014
Question

Issues with pausing the timeline and timing

  • January 15, 2014
  • 1 reply
  • 758 views

I am making a pretty simple home page news/image scroller that you see on many sites now. A rectangle box that goes through the various important stories and it also has controls to go forward and backward if needed. I have it laid out and I found a line of code to make it pause on each story for however long I want. I then added the first button to go back to the first frame (the first news story) at any time. When I test the movie the pausing is right and the button works. The problem is, the more I press the button the more the timing of the movie changes. It no longer paused for 10 seconds per story and it just starts pausing for random amounts of time. I know it has to be a code issue and I assume the code is stacking commands on top of each other for some reason and screwing up the timing. The code I am currently using for each story is:

stop();

setTimeout(play, 10000)

Like I said if I play the movie the timing thing works great. It stays on each story for 10 seconds then animates to the next just like I want. The button is what seems to mess it up but I need buttons for the user to control the whole thing. The code I am using for the button is:

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);

function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void

{

    gotoAndPlay(1);

}

Is my button code screwing this up? Any help would be appreciated thanks.

This topic has been closed for replies.

1 reply

sinious
Legend
January 15, 2014

Yes most likely a previous setTimeout is firing off, advancing you. To stop this nature, use a Timer or setInterval (I'd recommend Timer).

January 15, 2014

Thanks for the reply. So are you saying I should replace:

stop();

setTimeout(play, 10000)

With:

stop();

Timer(play, 10000)

??

January 15, 2014

Timer class and example source:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html

For example, on your first frame, define the timer once and set the number of times it fires to 1. Set a method to fire off once the timer ticks. Upon ever moving from one place to another you should reset the timer.

e.g. frame 1:

import flash.utils.Timer;

import flash.events.TimerEvent;

// stop playhead here

stop();

// only define the timer if it doesn't exist)

if (myTimer == null)

{

     // timer fires in 5 seconds (5000 milliseconds), just once

     var myTimer:Timer = new Timer(5000,1);

     // listen for that timers complete (5 seconds passed)

     myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandlerF);

     // function to handle timer once it completes

     function timerHandlerF(e:TimerEvent):void

     {

          // do what you want here, e.g. play() to advance the timeline

          play();

     }

}

// stop any existing timer and reset it so it fires once

myTimer.stop();

myTimer.reset();

// start the timer

myTimer.start();

On any other frame you'd just stop() and use the bottom 3 lines of code:

// stop playhead on new story

stop();

// stop and reset timer for caution

myTimer.stop();

myTimer.reset();

// restart timer

myTimer.start();

Every frame will make sure the timer performs correctly, constantly stopping it if it already is running, resetting it and waiting exactly 5 seconds before running code (play() in this example). Season to taste (change the delay time, change the syntax if you have this in a class, etc).


Thank you I will play around with this and see what I can do