ActiveDen

Help needed with setInterval

132 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • United Kingdom
  • Referred between 1 and 9 users
smoke_e_joe says

Any one help seem to be going in circles. Im building this animation which is mainly script base. Its all nearly done and client wants a skip button put in which is fine. the only problem is i have set intervals in some frames to shorten timeline usage to let scripted animation play before it moves on.

Now the problem is when the skip button is pressed it skips to the end of the animation but it goes back to the frame that had the setInterval on it.

Interval looks like this.

var nInterval = setInterval(Play, 5000);

function Play() { clearInterval(nInterval); nextFrame(); }

You can see that it just goes to next frame once the Interval is cleared. this works fine.

but….

when the the button is clicked it won’t seem to clearInterval and still runs it. This is the button script.

skip_btn.onRelease = function(){ delete this.onEnterFrame(); clearInterval(nInterval); gotoAndStop(115); }

so i’m trying to get it to clearInterval and stop at the end of the whole thing. It stops at the end but when the 5 second from the Interval is up it goes back to the frame it was on, and tries running it all again.

Anyone got any ideas.

Cheers

4 years ago
215 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • United Kingdom
  • Referred between 1 and 9 users
Ziyad says

Change:

var nInterval = setInterval(Play, 5000);

to

var nInterval:Number = setInterval(Play, 5000);

The intervalID in clearInterval(intervalID) likes to be an integer so if you define setInterval as one it’ll obey you :D.

Hope this helps,

Ziyad

4 years ago
2350 posts
  • Has been a member for 4-5 years
  • Won a Competition
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 50 and 99 users
wickedpixel says

if you need to call a function after an interval and only once… you can use the setTimeout(function_name, delay)
...

4 years ago
1513 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Bought between 1 and 9 items
  • Europe
  • Referred between 100 and 199 users
dSKY says

^^ yes you should use setTimeout, for this kind of stuff ,
setTimeout is undocumented in Actionscript 2.0 documentation , but it’s there :)

4 years ago
by
by
by
by
by