package slots.animations.reel { import com.greensock.TweenLite; import com.greensock.TweenMax; import com.greensock.easing.Back; import com.greensock.easing.Linear; import flash.display.MovieClip; import flash.events.Event; import flash.utils.getDefinitionByName; import slots.SlotsMain; public class AnimMain extends MovieClip { public var reelArray:Array; private var reelInstances:Array = new Array(); private var position:uint = 1; private var lastReel:Array; private var trap:Boolean = false; private var movePlace:uint; private var parentObj:SlotsMain; public function AnimMain(parentObj:SlotsMain,lastReel:Array) { super(); this.addEventListener(Event.ADDED_TO_STAGE,init); this.lastReel = lastReel; this.parentObj = parentObj; } private function init(e:Event):void { this.removeEventListener(Event.ADDED_TO_STAGE,init); this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.reelArray[this.reelArray.length-1]))); //AnimBase(this.reelInstances[0]).setMotionImage(); AnimBase(this.reelInstances[0]).y += (178*2); this.addChild(this.reelInstances[0]); this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.lastReel[2]))); //AnimBase(this.reelInstances[0]).setMotionImage(); AnimBase(this.reelInstances[0]).y += 178; this.addChild(this.reelInstances[0]); this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.lastReel[1]))); //AnimBase(this.reelInstances[0]).setMotionImage(); this.addChild(this.reelInstances[0]); this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.lastReel[0]))); //AnimBase(this.reelInstances[0]).setMotionImage(); AnimBase(this.reelInstances[0]).y -= 178; this.addChild(this.reelInstances[0]); this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.reelArray[0]))); //AnimBase(this.reelInstances[0]).setMotionImage(); AnimBase(this.reelInstances[0]).y -= (178*2); this.addChild(this.reelInstances[0]); } public function spinReel(movePlace:uint):void { //this.completeReel(); //var test:uint = 178 * movePlace;//(this.reelArray.length - 2); this.movePlace = movePlace; TweenMax.to(this.reelInstances,0.5,{y:"+=178",ease:Back.easeIn.config(3),immediateRender:false,onComplete:this.addNextSymbol}); } private function afterSpin():void{ this.position = 1; //this.removeLastSymbol(); this.dispatchEvent(new Event("spin_stop")); } private function completeReel():void{ for each(var t in this.reelArray){ this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.reelArray[t]))); if(this.position == 1){ AnimBase(this.reelInstances[0]).y -= (178*2); } else { AnimBase(this.reelInstances[0]).y -= (178) * this.position; } //AnimBase(this.reelInstances[0]).setMotionImage(); this.addChild(this.reelInstances[0]); this.position++; } this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.reelArray[this.reelArray.length-4]))); AnimBase(this.reelInstances[0]).y -= (178) * this.position; this.addChild(this.reelInstances[0]); this.position++; this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.reelArray[this.reelArray.length-3]))); AnimBase(this.reelInstances[0]).y -= (178) * this.position; this.addChild(this.reelInstances[0]); this.position++; this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.reelArray[this.reelArray.length-2]))); AnimBase(this.reelInstances[0]).y -= (178) * this.position; this.addChild(this.reelInstances[0]); this.position++; } private function addNextSymbol():void { this.removeLastSymbol(); this.reelInstances.unshift(createInstance(String("slots.animations.reel.Symbol"+this.reelArray[this.position]))); AnimBase(this.reelInstances[0]).y -= (178*2); //AnimBase(this.reelInstances[0]).setMotionImage(); this.addChild(this.reelInstances[0]); if(this.position < (this.reelArray.length-1)){ this.position++; } else { this.position = 0; } if(this.movePlace == this.position){ TweenLite.to(this.reelInstances,0.30,{y:"+=178",ease:Back.easeOut.config(3), onComplete:this.afterSpin,immediateRender:false}); } else{ TweenLite.to(this.reelInstances,0.15,{y:"+=178",ease: Linear.easeNone, onComplete:this.addNextSymbol,immediateRender:false}); } } private function removeLastSymbol():void { this.removeChild(this.reelInstances.pop()); } private function cleanStart():void { if(!this.trap){ this.y += 173*3; this.removeChild(this.reelInstances.pop()); this.removeChild(this.reelInstances.pop()); this.removeChild(this.reelInstances.pop()); this.removeChild(this.reelInstances.pop()); } this.trap = true; } private function createInstance(className:String):Object { var myClass:Class = getDefinitionByName(className) as Class; var instance:Object = new myClass(); return instance; } } }