PDA

View Full Version : clearInterval



earph
September 4th, 2003, 12:55 PM
How exactly would I clear this interval with my button?

//===============================
//PAUSE FUNCTION
//===============================
function pause(t, v)
{
t.interval = setInterval(unPause, v, t);
t.stop();
}

function unPause(t)
{
trace("clear & play");
clearInterval(t.interval);
t.play();
}

//===============================
// INITIATE FUNCTION
//===============================
pause(this,3000);

Would I clear the "t.interval" or do I clear the function "(pause)"?

grandsp5
September 4th, 2003, 01:08 PM
i don't know if you can assign it the name t.interval...thats like creating a variable called my.Sound or something, probably isnt very good. Try the following:

[AS]
//===============================
//PAUSE FUNCTION
//===============================
function pause(t, v)
{
tInterval = setInterval(unPause, v, t);
t.stop();
}

function unPause(t)
{
trace("clear & play");
clearInterval(tInterval);
t.play();
}

//===============================
// INITIATE FUNCTION
//===============================
pause(this,3000);

earph
September 4th, 2003, 02:01 PM
I see.... thanks for the tip.

But, the question is.... If I want to clear this interval... how would I do it. Would it be:

clearInterval(tinterval);
or would it be

clearInterval(pause);
or would it be something entirely different.

Thanks for the help!

grandsp5
September 4th, 2003, 02:04 PM
tInterval

earph
September 4th, 2003, 02:12 PM
So..... will that globally clear that interval? Cause that is basically what I need to do. I need to clear all the intervals when I hit my "back" button.

grandsp5
September 4th, 2003, 02:15 PM
you will need to clear each one by itself then. I dunno if you can create a global Interval and then clear that, ask someone like lost, kode, or sen.

earph
September 4th, 2003, 02:18 PM
Well..... nevermind the _global clear.... What if I want to clear the interval from some other loaded movie, would I do it like this:

_root.somemovie.anothermovie.clearInterval(pause);

I just need to shut the function totally off. I've even tried unloading the movie, but the output window shows that it's still running the interval function.

How can I turn it off?

grandsp5
September 4th, 2003, 02:38 PM
you dont clear the function name, you clear whatever you assigned the value of setInterval to. So it would be

_root.someMovie.anotherMovie.clearInterval(tInterv al);

earph
September 4th, 2003, 03:49 PM
Sorry, but it's not working for me. I've got a button on my _root that's calling down through 2 sub-movies, but it's not picking it up.

_root.movieLoader.subMovieLoader.clearInterval(sta ll);
Shouldn't it talk to what ever movies are loaded into the "movieLoader" and "subMovieLoader"?

grandsp5
September 4th, 2003, 03:57 PM
try tracing to make sure your path is correct

earph
September 4th, 2003, 04:05 PM
Not exactly sure how to do that with the clearInterval. I have a trace set up in my setInterval function, and it displays everytime the function runs. Is that what you mean?

Otherwise, I'm not sure how to run the trace for the "clearInterval".

Would it be something like this?

if(_root.movieLoader.subMovieLoader.clearInterval( stall);{
trace(it got cleared);}

grandsp5
September 4th, 2003, 04:09 PM
yeah (but you are missing a parenthesis there ;) ) I dunno if that will work because I don't know whether clearInterval returns a boolean value. You might just want to check the path.


trace(_root.movieLoader.subMovieLoader);

earph
September 4th, 2003, 04:17 PM
Wow... I learned something new. I never knew you good check paths like that.

Well..... the output window is showing "undefined", so I guess it's not picking up the path..... which sucks.

I mean.... that's a direct path... it should work, what else can we do?

If there is a movie called "orange" that is loaded into a blank mc called "movieLoader".... You should just be able to talk to the "orange" movie by calling "movieLoader", right?

grandsp5
September 4th, 2003, 04:21 PM
yes. if you load a movie clip into another, it takes on the attributes of the first and can be referenced using the instance name of the first.

earph
September 4th, 2003, 04:24 PM
This totally sucks then.... cause the path should be right. I can't think of anything else right now. I think I need to step away and go get a drink real fast... I'll be back to stare at this thing some more.

I appreciate all the help......

grandsp5
September 4th, 2003, 04:29 PM
welcome

lac
September 4th, 2003, 04:41 PM
Hi,

try trace(targetPath(_root.movieLoader.subMovieLoader) );

that should give you the same path that you put in if it's correct. If not then it will return undefined I think.

The other thing to try is in the onClipEvent(load) of the subMovieLoader put... trace(targetPath(this)); and that will give you the path to that movie clip.

Hope this helps.

Liz

grandsp5
September 4th, 2003, 04:48 PM
or you can just

trace(this);

same thing.

earph
September 4th, 2003, 04:51 PM
Wow... that's another kewl tip also... thanks!

But... still no dice. Not working.k

The trace returned "_level0.movieLoader.subMovieLoader", so I inserted on my _root button like this:

_level0.movieLoader.subMovieLoader.clearInterval(s tall);

But... it's still not clearing it out. This is lame... :(

grandsp5
September 4th, 2003, 04:59 PM
dunno man. sorry. is your interval named stall? and did you set it right? not sure

earph
September 4th, 2003, 05:00 PM
OMG!!! It works!! I can't believe we had to go through all of that!!

Ugh... something so simple!

Oh well... so relieved now.. :)

Beers for everyone is this thread! Gulp... Gulp... Gulp....

I appreciate it.

grandsp5
September 4th, 2003, 05:03 PM
what was it?

heh and I can't actually drink for 4 more years..

legally :whistle:

senocular
September 4th, 2003, 05:07 PM
what exactly was the problem?

btw, I see a lot of pathing.clearInterval() when clearInterval is a global function and the pathing is for the interval being cleared

clearInterval(path.path.interval);

you can find some extended setInterval functions here:
http://proto.layer51.com/d.aspx?f=857
http://proto.layer51.com/d.aspx?f=877

and here is a setTimeout:

_global.setTimeout = function(a,b,c, args){
// for a basic function call:
if (typeof a == "function"){
args = arguments.slice(2);
var ID, func = function(){
a.apply(null, args);
clearInterval(ID);
}
ID = setInterval(func, b, args);

// for an object method call:
}else{
args = arguments.slice(3);
var ID, func = function(){
a[b].apply(a, args);
clearInterval(ID);
}
ID = setInterval(func, c, args);
}
return ID;
}
_global.clearTimeout = clearInterval;
more on setinterval (http://www.umbc.edu/interactive/flash/tutorials/showpage.php?p=setInterval)

earph
September 4th, 2003, 05:07 PM
Just subtracting the "level0" or the "_root" off the front of the code like this:

movieLoader.subMovieLoader.clearInterval(stall);

I can't believe it was something so simple.

grandsp5
September 4th, 2003, 05:10 PM
well i guess i was right, and I deleted that post because i thought it wouldnt work

grandsp5
September 4th, 2003, 05:12 PM
sen...what on earth does that code do?

got it when i stared long enough..i think

earph
September 4th, 2003, 05:32 PM
HOLD ON!!!

No guys.... that didn't solve the problem.... ugh.. lame.

The code:

movieLoader.subMovieLoader.clearInterval(stall);
Doesn't fix the problem.

lac
September 4th, 2003, 05:36 PM
Did you look closely at what Sen posted? He wants you to do
clearInterval(<path>.stall);

Not put the path at the beginning of the call to clearInterval

Liz

earph
September 4th, 2003, 05:40 PM
Like this?

clearInterval(movieLoader.subMovieLoader.stall);

Not working......

earph
September 4th, 2003, 05:43 PM
REMINDER: Here's the "setInterval" in the loaded movie:

function pause(t, v)
{
stall = setInterval(unPause, v, t);
t.stop();
}

function unPause(t)
{
clearInterval(stall);
t.play();
}

pause(this,3000);
This should be a simple route through the paths.... why is it not working?

uhhhhh!!!!!

lac
September 4th, 2003, 05:54 PM
What happens if you call your unPause function?

_root.movieLoader.subMovieLoader.unPause(t);

Liz

senocular
September 4th, 2003, 05:55 PM
use

t.stall = setInterval(unPause, v, t);

earph
September 4th, 2003, 05:59 PM
Sorry LAC... that didn't work either.

SENOCULAR My setInterval is working fine with everything.... I just can't get my buttons on my _root to route back to the loaded movies and turn the "setInterval" off.

Problem with the path.....

earph
September 4th, 2003, 06:01 PM
Do I need to put a "targetPath" somewhere? Would that help?

I mean, what's the deal. I'm totally unloading the movie with the "setInterval" in it, and it's still running the function.

This is totally whack... :(

senocular
September 4th, 2003, 06:13 PM
your function is a function in root. when you call the function, any variables defined in that function (if not local with var which they arent), are assigned in _root. So, when you call your pause, stall is being set in _root. Clearing stall would mean using clearInterval(_root.stall) ... or just stall... or _level1.stall - whatever - whereever that function is. Putting that stall in the movieclip itself, however, with t.stall, lets you have that interval variable direcltly associated with that movieclip and not the timeline of the function. You would want this 1) so you can specificially clear the interval of any specific movieclip with clearInterval(myMovie.stall) and 2) because stall is defined in that timeline of the function (_root) calling that function twice would mean over-writing an interval variable that was saved before. In setting a new stall, any previous stall interval is lost thereby only allowing one stall variable at a time - not desired. So instead, set stall in t and clear it from t.

earph
September 4th, 2003, 06:21 PM
Is this what you mean:

//===============================
//PAUSE FUNCTION
//===============================
function pause(t, v)
{
t.stall = setInterval(unPause, v, t);
t.stop();
}

function unPause(t)
{
trace("clear & play");
clearInterval(t.stall);
t.play();
}

//===============================
// INITIATE FUNCTION
//===============================
pause(this,3000);

The button on _root with this code:

clearInterval(movieLoader.subMovieLoader.stall);
Is that what you're talking about? That's not working either.... :(