setTimeout in actionscript 2
I'm using this
var timer2 = setTimeout(checkValue2, 2000);
as a frame action in Frame 2, which then triggers checkValue2 which is a piece of function in Frame 1 where all the _global. variables are as well.
clearTimeout(timer2);
gotoAndStop(3); //goto lvl3 - throw
addStage3();
so it'd then goto Frame 3, but, the problem is even after clearing, the frame animation still loops every 2 seconds, regardless whether i'm using setTimeout or setInterval. Do you might know of any other way where what I need is, after 2 seconds in Frame 2, it'd then 开发者_开发知识库move to Frame 3, which I don't want it to go anywhere yet.
am i doing something wrong here :(
You should not need to use clearTimeout() at all, because setTimeout() executes a function only once. Are you sure you've stopped the animation after calling setTimeout in frame 2 in the first place?
EDIT
Your movie probably loops at a later point, so that frame2 is executed over and over again. To find the cause of the problem, do this:
Add an event listener to frame 1 of your main timeline:
onEnterFrame = function () : Void { trace ("current: " + _currentFrame) }
Run your program and check the trace output: At which point does the loop occur?
If the loop always happens at the same frame: Check that frame's content and see if you have any gotoAndPlay(), or play() in it. Also, re-check that your stop() calls are not nested within function declarations or somehow unreachable (e.g. within if/else statements which never execute, or after some other code that would stop the script or jump to another frame).
If the loop happens erratically: See if you have any ActionScript that executes randomly or at timed intervals. btw: You can use the MovieExplorer window to find all AS within your FLA.
精彩评论