import mx.utils.Delegate class MCAnimator { public static var LOOP : Number = 1; public static var FORWARD : Number = 2; public static var BACKWARDS : Number = 4; private var movingMC : MovieClip; private var playDirection : Number; private var isLooping : Boolean; public function MCAnimator( mc: MovieClip ) { this.movingMC = mc; this.isLooping = false; this.playDirection = 0; } public function play( flags: Number ) { if( ( flags & FORWARD ) == FORWARD ) { this.playDirection = 1; } else if( ( flags & BACKWARDS ) == BACKWARDS ) { this.playDirection = -1; } if( ( flags & LOOP ) == LOOP ) { this.isLooping = true; } if( this.playDirection != 0 ) { this.movingMC.onEnterFrame = Delegate.create( this, onEnterFrame ); } else { trace( "MCAnimator ussage error: direction not specificied" ); } } public function stop( ) { delete this.movingMC.onEnterFrame; } private function onEnterFrame( ) { var actual : Number = this.movingMC._currentframe; var total : Number = this.movingMC._totalframes; var nextStep: Number = actual + this.playDirection; if( this.isLooping == false ) { if( nextStep> total ) { nextStep = total; this.stop( ); } if( nextStep< 1 ) { nextStep = 1; this.stop( ); } } else { if( nextStep == 0 ) { nextStep = total; } if( nextStep == total+1 ) { nextStep = 1; } } this.movingMC.gotoAndStop( nextStep ); } }