Copy link to clipboard
Copied
How do I get the Interval to keep from repeating after it's used once? Because I tried clearInterval but I couldn't get it working.
When my code looks like this, with ClearInterval, it refuses to execute my action, which is to change scenes after a short interval:
(Pardon if there is some formating errors, I had to reformat it for the Internet)
Code with clearInterval command |
---|
|
However, when my code looks like this it refuses to stop looping:
Code without ClearInterval command |
---|
|
Copy link to clipboard
Copied
If you only want to execute your function once, use either setTimeout
or use a Timer
Timers are in most cases a more precise and flexible solution.
Copy link to clipboard
Copied
If you insist on using setInterval - you need to declare interval id in a higher scope so that you can clear it later:
stop();
var myInterval:uint;
Kollektiv.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);
function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void
{
gotoAndPlay(29);
myInterval = setInterval(fl_ClickToGoToNextScene_14, 3000);
}
function fl_ClickToGoToScene_14():void
{
clearInterval(myInterval);
MovieClip(this.root).gotoAndPlay(1, "Testside");
}
I suggest you use Timer instead:
stop();
import flash.events.TimerEvent;
import flash.utils.Timer;
var timer:Timer = new Timer(3000, 1);
timer.addEventListener(TimerEvent.TIMER, fl_ClickToGoToScene_14);
function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void
{
timer.start();
gotoAndPlay(29);
}
function fl_ClickToGoToScene_14(event:TimerEvent):void
{
timer.stop();
MovieClip(this.root).gotoAndPlay(1, "Testside");
}
Copy link to clipboard
Copied
I will use a timer, thank you!
I used your timer code, but now the clip/scene won't play at all. I don't get any errors in the compiler though.
I know I should probably learn Actionscript properly instead of copying codes, but with a deadline coming up real fast I really don't have time.
EDIT: Figured it out. I just had to add
Kollektiv.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);
after the timer function. Thanks guys.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now