Skip to main content
February 13, 2009
Answered

More than one Pause Timer

  • February 13, 2009
  • 1 reply
  • 647 views
Hi,

I'm animating a sunset and would like it to pause for a few seconds between motion tweens. I have one "pause" timer set up in actionScript:

this.stop();

var timelinePause:Timer = new Timer(6000, 1);
timelinePause.addEventListener(TimerEvent.TIMER, timerHandler);
timelinePause.start();

function timerHandler(evt:Object):void {
this.play();
}

but when I add another in a later frame, I get these errors:
1151: A conflict exists with definition timelinePause in namespace internal.
This topic has been closed for replies.
Correct answer
That's perfect! Thank you for explaining it in detail!

TS

1 reply

Inspiring
February 13, 2009
t_sharley,

> but when I add another [pause script] in a later frame, I get these
> errors:
> 1151: A conflict exists with definition timelinePause in namespace
> internal.

It sounds like you're trying to redeclare your timelinePause instance a
second time in the same scope (that is, in the same timeline), which isn't
allowed in AS3. All you have to do is get rid of the word "var" and the
:Timer type in any subsequent frames. You only need the instance declared
one time, and then you can re-use it. Same goes for the function.

// Frame 1
this.stop();
var timelinePause:Timer = new Timer(6000, 1);
timelinePause.addEventListener(TimerEvent.TIMER, timerHandler);
timelinePause.start();
function timerHandler(evt:Object):void {
this.play();
}

// Frame 5 (for example) ...
this.stop();
timelinePause = new Timer(6000, 1);
timelinePause.addEventListener(TimerEvent.TIMER, timerHandler);
timelinePause.start();

See the difference? If you re-instantiate your Timer instance in frame
5, you'll have to re-associate it with your custom timerHandler() declared
in frame 1, but you don't have to retype that function declaration later,
because Flash remembers what you mean by "timerHandler". Also, the second
line -- just beneath "this.stop();" -- omits the word "var", which is what
caused that error message.

But you can even do this more succinctly. Check it out:

// Frame 1
this.stop();
var timelinePause:Timer = new Timer(6000, 1);
timelinePause.addEventListener(TimerEvent.TIMER, timerHandler);
timelinePause.start();
function timerHandler(evt:Object):void {
this.play();
}


// Frame 5
this.stop();
timelinePause.start();

In this case, you're completely reusing everything. You simply tell the
timeline to stop again in frame 5, then instruct the already existing Timer
instance (timelinePause) to restart. If you wanted to change the duration
of the pause, you could access the Timer.delay property of that instance
without having to re-declare. Like this:

// Frame 1
this.stop();
var timelinePause:Timer = new Timer(6000, 1);
timelinePause.addEventListener(TimerEvent.TIMER, timerHandler);
timelinePause.start();
function timerHandler(evt:Object):void {
this.play();
}

// Frame 5
this.stop();
timelinePause.delay = 3000;
timelinePause.start();

// Frame 10
this.stop();
timelinePause.delay = 8000;
timelinePause.start();

Let me know if that makes sense. :)


David Stiller
Co-author, Foundation Flash CS4 for Designers
http://tinyurl.com/5j55cv
"Luck is the residue of good design."


Correct answer
February 15, 2009
That's perfect! Thank you for explaining it in detail!

TS