import flash.utils.Timer; import flash.events.TimerEvent; import com.greensock.TweenLite; import com.greensock.easing.*; // sets the initial wheel rotation to 0. wheel.rotation = 0; // this is the time in seconds that you want the first few spins (not the final spin) to last. var spinTime:Number = 4; // this is the number of spins before the final spin var numSpins:Number = 0; // ** will be swapped out for dynamically generated multiplier. // get bonus number from host var bonusNum:Number = root.loaderInfo.parameters.KenoBonusNumber; // get super bonus number from host var superbonusNum:Number = root.loaderInfo.parameters.KenoSuperBonusNumber; // generate random number function randomNumber(min:Number, max:Number):Number { return Math.floor(Math.random() * (1 + max - min) + min); } // use randomNumber to create a number between 0 and 2 var RandomNumMod:Number = randomNumber(0,2); // use set wheel selection array values based on a number 0 thru 2 var wheelSections:Array = new Array(); switch(RandomNumMod) { case 0: wheelSections[1] = []; wheelSections[1][2] = 2170; //Dark Blue No Bonus wheelSections[1][3] = 355; wheelSections[3] = []; wheelSections[3][4] = 340; //Light Green wheelSections[3][5] = 326; wheelSections[4] = []; wheelSections[4][5] = 283; //Black wheelSections[4][6] = 268; wheelSections[5] = []; wheelSections[5][6] = 313; //Dark Green wheelSections[5][10] = 298; wheelSections[10] = []; wheelSections[10][12] = 75; //Light Grey wheelSections[10][20] = 57; break; case 1: wheelSections[1] = []; wheelSections[1][2] = 2412; //Red No Bonus wheelSections[1][3] = 237; wheelSections[3] = []; wheelSections[3][4] = 190; //Olive Green wheelSections[3][5] = 175; wheelSections[4] = []; wheelSections[4][5] = 160; //Yellow wheelSections[4][6] = 145; wheelSections[5] = []; wheelSections[5][6] = 222; //Purple wheelSections[5][10] = 205; wheelSections[10] = []; wheelSections[10][12] = 75; //Light Grey wheelSections[10][20] = 57; break; case 2: wheelSections[1] = []; wheelSections[1][2] = 2292; //Grey No Bonus wheelSections[1][3] = 117; wheelSections[3] = []; wheelSections[3][4] = 103; //Light Blue wheelSections[3][5] = 88; wheelSections[4] = []; wheelSections[4][5] = 40; //Dark Yellow wheelSections[4][6] = 25; wheelSections[5] = []; wheelSections[5][6] = 222; //Purple wheelSections[5][10] = 205; wheelSections[10] = []; wheelSections[10][12] = 75; //Light Grey wheelSections[10][20] = 57; break; default: wheelSections[1] = []; wheelSections[1][2] = 2170; //Dark Blue No Bonus wheelSections[1][3] = 355; wheelSections[3] = []; wheelSections[3][4] = 340; //Light Green wheelSections[3][5] = 326; wheelSections[4] = []; wheelSections[4][5] = 283; //Black wheelSections[4][6] = 268; wheelSections[5] = []; wheelSections[5][6] = 313; //Dark Green wheelSections[5][10] = 298; wheelSections[10] = []; wheelSections[10][12] = 75; //Light Grey wheelSections[10][20] = 57; break; } var finalSpinRotation:Number = wheelSections[bonusNum][superbonusNum]; // Timer for the first few spins var timer:Timer = new Timer(spinTime * 1000, numSpins); timer.addEventListener(TimerEvent.TIMER, startSpin); timer.start(); // Timer for the final spin var finalSpinTimer = new Timer(numSpins * 1000, 1); finalSpinTimer.addEventListener(TimerEvent.TIMER, winSpin); function startSpin(event:TimerEvent):void { // this is the tween that does the first few spins - this uses Linear.easeNone, // which is no easing because the default is an easeOut. We only want the easeOut // on the final spin. var currentRotation:Number = wheel.rotation; if (finalSpinRotation < currentRotation) { finalSpinRotation += 360; } TweenLite.to(wheel, spinTime, {rotation:360, ease:Linear.easeNone}); finalSpinTimer.start(); } function winSpin(event:TimerEvent):void { timer.stop(); //trace(wheel.rotation); greensockSpin(); } function greensockSpin():void { // this is the final spin. The default easing is Regular.easeOut - // see demo at http://www.greensock.com/tweenlite/ for more on easing functions // The second value "2" is the number of seconds this last rotation will take. This keeps the time of the // rotation constant. You may want to do some math to make the speed of the final rotation constant. TweenLite.to(wheel, 2, {rotation:finalSpinRotation}); }