-
Clear Interval Within Function
Hello,
I'm working in Flash V8.
I want to clear an Interval within a function but I'm not sure how. setInterval is cleared fine when not within the function, but I want to call it from a MCbutton. Could someone please show me how to do such a thing. Thank You, Jacob
//For Loop to Animate Text
function setAnimate():Void {
//Animated Property Changes
containerMC1._alpha = nChange++
containerMC1._xscale = nChange++
containerMC1._yscale = nChange++
//Counter
nTimes++
//Clears Interval
if(nTimes >= 35) {
clearInterval(nInterval);
}
}
var nChange:Number = 0;
var nTimes:Number = 0;
//Problem Area....!!!
//Start Interval Function
function startInterval():Void {
var nInterval:Number = setInterval(setAnimate, 8);
}
-
Qwaizang:syntax_entity_
The reason why your interval is not being cleared is because the scope of the variable "nInterval" is localized within startInterval().
To fix this, write your code as follows:
Code:
var nChange:Number = 0;
var nTimes:Number = 0;
var nInterval:Number = undefined;
//For Loop to Animate Text
function setAnimate():Void {
//Animated Property Changes
containerMC1._alpha = nChange++;
containerMC1._xscale = nChange++;
containerMC1._yscale = nChange++;
//Counter
nTimes++;
//Clears Interval
if(nTimes >= 35) {
clearInterval(nInterval);
}
}
//Start Interval Function
function startInterval():Void {
nInterval = setInterval(setAnimate, 8);
}
This will make the scope of nInterval more broad so that more than one function can access it.
+Q__
-
Brilliant
Thanks, I would have not figured that one out.
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
|