This is a weird one. I have setInterval action in frame two that is inside a movieClip that inside a swf that is loaded into a root holder.
Now, when the setInterval is cleared, it moves that movieClip back to frame one. If I unload that swf before the setInterval is cleared, the root timeline moves to frame 1. Its like the setInterval is _global or something. I have fixed it by using an onEnterFrame, but I need the animation to be faster.
Any ideas?
Thanks,
Josh
Hey Rhamej. Can you post the code you use where you clear the interval?
You bet. =)
// frame one
stop();
q = 1;
var blah;
// frame 2
stop();
function showIt() {
_parent.textSound.start();
if (q<_parent.myText.length) {
textBox = _parent.myText.substring(0, q);
q++;
} else {
textBox = _parent.myText;
gotoAndStop(1);
clearInterval(blah);
}
};
}
blah= setInterval(showIt,10);
My guess is its changing frame before it clears, at least thats what it looks like, use:
// frame one
stop();
q = 1;
var blah;
// frame 2
stop();
function showIt() {
_parent.textSound.start();
if (q<_parent.myText.length) {
textBox = _parent.myText.substring(0, q);
q++;
} else {
textBox = _parent.myText;
clearInterval(blah);
gotoAndStop(1);
}
};
}
blah= setInterval(showIt,10);
I see. My suggestion would be to check if there are any intervals active when you unload the swf. And if there are, clear them.
mathan99, I had tried that earlier, it didnt work. I even cleared the interval in frame one just to make sure. I was typing from memory above, and those lines are switched in the fla.
BlueNar, I think you are on to something. But I always thought that a var declared in a time line was specific only to that time line. And since the swf was unloaded, the setInterval would automatically be killed? Set intervals have always been kinda tricky to use for me. Sometimes they work, and some times they wreak havoc on everything. I’ll try adding the clearInterval to the button that unloads the swf on the root timeline. I’ll post back =)
You’re right about vars being unloaded with the swf, but “blah” is the ID linked to the interval. Clearing the data in blah only destroys the link between the two, leaving the interval still running. At least, thats what I think
just a quicky,
why is th }; there?
function showIt() {
_parent.textSound.start();
if (q<_parent.myText.length) {
textBox = _parent.myText.substring(0, q);
q++;
} else {
textBox = _parent.myText;
clearInterval(blah);
gotoAndStop(1);
}
};
}
Post a fla?
scotty(-:
i think it may be to do with the gotoAndStop(1) line
set interval has problems understanding the scope eg (this)
so u can also setInterval like.
[AS]blah= setInterval(this,“showIt”,10);[/AS]
see the link for more details on setInterval.
http://www.senocular.com/flash/tutorials/faq/#setintscope
LaterEdit: I’ve now seen the post of MacaroniTed. Lol I should read better before staring to write this much. Anyway. You do have to speciffy the scope for the setInterval function. But I think that you’ll still have to specifiy inside that function this.gotoAndStop(1); to prevent the main timeline skipping before clearing the interval. Read Below
Boys boys boys.
The blah variable only contains the id for the setInterval. It’s just a number really. SetInterval as rhamej suggested is sort of a global function that will keep repeating until it’s cleared.
So this problem it’s not about where you define your variable that holds the id so you can later kill the setInterval, but it’s about the scope where the setInterval runs.
Thing is that a setInterval will keep repeating no matter where you set it.
Why it move back your timline to frame one ?
Because if you remove the swf then _parent.myText.length will be undefined then SURPRISINGLY q<_parent.myText.length will evaluate to true q beeing any set number or undefined if it’s inside that current timeline (because you remove it).
So the next time the function repeats it will basically go through the else statement and execute the gotoAndStop(1);
How do you stop this? Simply put a this before that like this.gotoAndStop(1).
This however will not work because the this keyword inside a function that is run by setInterval doesn’t has a value if you don’t first set the scope of the setInterval.
So we’ve come to the coolest part. You CAN set the scope where the function set by setInterval will be run just by sending the function.
// frame one
stop();
q = 1;
var blah;
// frame 2
stop();
function showIt() {
_parent.textSound.start();
if (q<_parent.myText.length) {
textBox = _parent.myText.substring(0, q);
q++;
} else {
textBox = _parent.myText;
clearInterval(blah);
this.gotoAndStop(1);
}
};
}
blah= setInterval(this,"showIt",10);
Hope this works :).
Bad frikkin arse :hugegrin: That was what i was looking for. Thanks!