Hi - i am making a simple slideshow in AS2 (Flash CS3). I got all the core logic working fine in a FLA frame action - now trying to externalize it into a class. The first snag I hit was in trying to setTimeout -- when I passed a class method as the setTimeout function, it no longer could talk to the class variables/methods. I fixed this by passing along an instance of the class to the class method called by setTimeout something like this:
setTimeout(myMethod,delay,classInstance);
Now I've got a similar problem with my Tween.onMotionFinished() handler -- i want it to call another method in my class but it doesn't know what the class is or how to access it.
How should this be accomplished? I've tried a similar trick in which I try to stash a class instance inside the tween (through bracket syntax eg. myTween["classInstance"] = this; but this doesn't seem to work.
Is this a case where I basicallyneed to create an event listener in my class & then just send an event out when the tween finishes? Or is there a simpler way to let the tween know about the class (without relying on instance names of the class itself)?
I'm still new to OOP so not completely got my head around what can/can't access my class methods/variables especially when I'm creating objects like Tweens inside my class.
here's my current SlideShow.as class:
and then I just create a slideshow from an existing framesequence MC (who has stop() on frame 1) in the FLA thusly:Code:/* imports */ import mx.transitions.Tween; import mx.transitions.easing.*; /* class to create a crossfading slideshow from an on-stage MC comprised of a framesequence of slides. */ class com.pixelfarminteractive.slides.SlideShow { /* variables */ private var _slideshowMC:MovieClip; private var _slideshowOldMC:MovieClip; private var _easeType = mx.transitions.easing.Regular.easeOut; private var _easeTime:Number;//stored in sec private var _holdTime:Number;//stored in millisec private var _currentSlideNum:Number; private var _numSlides:Number;//how many frames in the slideshowMC? private var _crossFade:Tween; /* constructor */ public function SlideShow(slideMC:MovieClip,easeTimeSec:Number,holdTimeSec:Number,numSlides:Number) { _slideshowMC = slideMC; _slideshowOldMC = _slideshowMC.duplicateMovieClip("slideshowOld_mc",_slideshowMC._parent.getNextHighestDepth()); _easeTime = easeTimeSec; _holdTime = 1000*holdTimeSec; _numSlides = numSlides; _currentSlideNum=1; } private function tweenTo(mc:MovieClip, attribute:String, dest:Number):Tween { return new Tween(mc, attribute, _easeType, mc[attribute], dest, _easeTime, true); } public function start():Void{ _global['setTimeout'](fadeInNext,_holdTime,this); //setInterval(fadeInNext,_holdTime,this); trace("starting Slideshow in "+_holdTime+" milliseconds. currentSlideNum = "+_currentSlideNum); } public function fadeIn(n:Number):Void{ //function to fade in the corresponding slide# of slideshow_mc trace("fadeIn _slideshowOldMC = "+_slideshowOldMC+" _slideshowMC="+_slideshowMC); _slideshowOldMC.gotoAndStop(_slideshowMC._currentframe); _slideshowMC._alpha=0; _slideshowMC.gotoAndStop(n); _slideshowMC._alpha=100; _crossFade = tweenTo(_slideshowOldMC,"_alpha",0); _crossFade["thisClass"] = this; _crossFade.onMotionChanged = function(){ trace("_crossFade.position="+this.position); } _crossFade.onMotionFinished = function(){ //_slideshowOldMC.removeMovieClip(); _global['setTimeout'](this["thisClass"].fadeInNext,this["thisClass"]._holdTime,this["thisClass"]); } } public function fadeInNext(c):Void{ var thisClass=c; if (_currentSlideNum+1>_numSlides){ _currentSlideNum=1; trace("fadeinNext starting over"); }else{ _currentSlideNum++; trace("fadeinNext advancing to "+thisClass._currentSlideNum); } trace("fadeinNext _currentSlideNum="+_currentSlideNum); thisClass.fadeIn(_currentSlideNum); } }
Code:import com.pixelfarminteractive.slides.SlideShow; //SlideShow(slideMC:MovieClip,easeTimeSec:Number,holdTimeSec:Number,numSlides:Number) var ss = new SlideShow(slideshow_mc,2,2,4); ss.start();




Reply With Quote
