Set Interval Help Plz


 I have an _mc that fades is and then fades out. I want to pause the _mc at frames 1, 25, and 50 of the _mc's timeline and then have it start all over again. I have the following code on the first frame of the _mc :

function timer(){
trace(“5 seconds has passed…going to next scene”);;
timeOut = setInterval(timer, 5000);

and then on frames 25 and 50 i have:

timeOut = setInterval(timer, 10000);

The _mc is on the main timeline. The problem is that the _mc plays fine with the pauses the first time but then as the _mc continues to loop, the pauses dont last as long as they are set to in the above code. Its as if the set interval is not obeyed anymore. Could anyone plz comment on this and tell me what i am doind wrong?

wel first thing i notice is that


does nothing.


on the other hand would work fine - dont forget Action Script is like Java Script in that its case sensitive…

also, i just tried your code with one slight modification, i changed to play() which could be your problem… youve stopped the main timeline and you dont start it again, hence you dont reach frames 25 or 50 and therefore you wont change it to an interval of 10 secs…

hope this helps, (only had a quick glance at it ;))


Firat let me say thanks for the reply Prophet. Are you saing the stop(); command in the _mc is stopping the maintimeline? All commands and their paths are relative to the _mc. Are they not???

as prophet said you must be careful with the names… case sensitive.
Because you were not using corect clearInterval, every time you accesed the “setInterval(timer, 5000);” it practically created a new repeating every 5seconds “timer” function.
All worked in parallel and as timed passed, the instances multiplicated and the chances for any one of them that 5 seconds had pass grew proportionaly.
So basicaly at some moment you had multiple functions shouting at your movie “;”… thats why the pauses were smaller and smaller.
Sorry for my english… I hope i solve somehow the mistery :wink:

Thanks Virusescu but I changed and made sure that the “case” were all in order and the same problems are still occuring as stated above.

Try putting clearInterval(timeout); on frames 25 and 50.
I dont understand how your movie is set up, you say it is situated on the main timeline, yet you are referencing it by myHome.bigsun I would have thought , like Prophet, that play() would be better and i dont really understand why your code works at all.

The _mc is on the main timeline. myHome is the global variable name I gave to the movie. When I use; it is with reference to the “bigsun” _mc on the main timeline.

Stringy its clearInterval(timeOut) :wink: lol
but thats what i thought originally but there is no real point in doing this as you will never reach this frame with the code he has.
you are stopping the main timeline (the one with 50 frames) and you are only playing a child movieclip. Hence, unless you have some code in this movieclip myHome.bigsun which says

or a _root.goto action, you will not reach frame 25, let alone 50 to change the setInterval.

hence your problem is not with the setInterval function but rather with basic timeline navigation (and case sensitivity in the clearInterval function :wink: ). seriously, in the function add the following line:


and change the typo in the clearInterval and you should start to see results you wanted to see… trust us!!


PS if you dont believe us or it still doesnt work for some obscure reason, post an fla!

Oops,thats was sloppy especially in light of previous advice.

Hi guys,

Here is the .fla's to see whats happening. Hit the home button a few times and just wait and see that the intevals are not working. They work at first but then they do not. I have made sure the "case" are set properly and I have changed the command to play();. Thanks for all your help.

ok u wernt clearing intervals properly…
i swapped the button code for this:

on (press) {
	if(_root.homeLoaded == true){

which will also stop the black flicker you are getting at the start of it :wink:

and on the first frame i have

_root.homeLoaded = true
function timer(){
	//trace("5 seconds has passed...going to next frame");
timeOut = setInterval(timer, 5000);

minor adjustments but they now work :wink:

dont forget FMX processes code line by line… :wink: