-
Clear Interval problem
Hello there folks, I have a prob when clearing an interval after calling it over a variable.
I ve created a method to increase the scale of a movie clip. the method is saved to a .as file and goes like this :
function addScale(clip1:MovieClip, intsc:Number, scaleNum:Number){
clip1._xscale += scaleNum;
clip1._yscale += scaleNum;
if(clip1._xscale > 100){
clearInterval(intsc);
}
updateAfterEvent();
}
and the call (in the 1st frame of the timeline) goes like this :
var intScale = setInterval(addScale, 30, chooseText, intScale, 1.6);
the problem is that my interval is not cleared in my method! dont know why. the movie clips keeps growing and growing...
The function is working (the animation is performed - but as I said doesn't stops), if I put a trace in the if statement, I get the result (the if statement is accessed in other words)....
I dont underestand though why the intScale value is not passed in my function to the intsc parameter , so I can clear this interval...
when I write the function without parametres (thus focused to animate a specific movie clip) the clearInterval works fine ....
but I want it like this, so I can call it 5 times to animate 5 diff movie clips!
-
Maybe you can adapt this to what you are trying to do...
Code:
function addScale(clip1:MovieClip, scaleNum:Number) {
clip1._xscale += scaleNum;
clip1._yscale += scaleNum;
if (clip1._xscale >= 100) {
clearInterval(clip1.intScale);
}
updateAfterEvent();
}
chooseText.intScale = setInterval(addScale, 30, chooseText, 1.6);
-
finally a proper answer!
m8 , thx A lOT ! it is working properly! chheeers!
-
As an alternative approach to the same thing, this uses variable scope to allow you to use setInterval without needing to set any properties on the MovieClip.
Code:
function addScale(clip1:MovieClip, scaleNum:Number) {
var id = setInterval(doScale,30);
function doScale() {
clip1._xscale += scaleNum;
clip1._yscale += scaleNum;
if (clip1._xscale>=100) {
clearInterval(id);
}
updateAfterEvent();
}
}
addScale(chooseText,1.6);
G
-
Thats an interesting approach my friend , I like it. I m goin to see how it works as well!
Thank you both for the quick answers!
Last edited by NoobGeek; 07-22-2008 at 10:03 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|