Set Interval Help Plz

Hello,

 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 :

stop();
function timer(){
trace(“5 seconds has passed…going to next scene”);
myHome.bigsun.play();
clearInterval(timeout);
};
timeOut = setInterval(timer, 5000);

and then on frames 25 and 50 i have:

stop();
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

clearInterval(timeout)

does nothing.

clearInterval(timeOut)

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 myHome.bigsun.play() 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 ;))

Prophet.

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 “myHome.bigsun.play();”… 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 myHome.bigsun.play(); 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

_root.play()

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:

play()

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

Prophet.

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){
		_root.load.bigsun.gotoAndStop(1)
	}
	else{
		_root.load.loadMovie("home.swf");
	}
}

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
stop();
clearInterval(timeOut);
function timer(){
	clearInterval(timeOut)
	//trace("5 seconds has passed...going to next frame");
	play();
};
timeOut = setInterval(timer, 5000);

minor adjustments but they now work :wink:

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

Prophet.