Hi I’m trying to write my first AS 2.0 class that is basically will fade clips in and out. Here’s my code:
class FadeControls extends MovieClip {
// variables
private var currentAlpha:Number;
private var finalAlpha:Number;
private var faderInterval;
private var ease:Number = .1;
// constructor
function FadeControls() {
trace("FadeControls Class loaded on "+this);
}
public function fadeTo(inputAlpha:Number):Void {
// begins the fade interval and sets initial values
currentAlpha = _alpha;
trace("current alpha: "+currentAlpha); // works
finalAlpha = inputAlpha;
// trace(finalAlpha); // also works
faderInterval = setInterval(fader, 33);
}
private function fader():Void {
trace("current alpha in fader(): "+currentAlpha); // breaks! why!?
var increment:Number;
increment = (finalAlpha-currentAlpha)*ease;
currentAlpha += increment;
_alpha = currentAlpha;
if (Math.abs(finalAlpha-currentAlpha)<=1) {
_alpha = finalAlpha;
clearInterval(faderInterval);
}
}
}
I’m having a problem with my variables coming up “undefined” when I try to use them in the fader() function. I can trace the variables “currentAlpha” and “finalAlpha” just fine within the fadeTo() function. Why do they resolve as undefined in the fader() function? I’ve been using Senocular’s OOP tutorial on Kirupa here and can’t see what makes mine break. Any help is greatly appreciated!