southill
12/1/2017 - 4:30 AM

MyLottery With Fla Frame Step

MyLottery With Fla Frame Step

function MyLottery(){
		this.ems = new gm.EM;
	}
	MyLottery.prototype = {
		init : function (_config) {
			var self = this;
			self.btnStart = _config.btnStart;
			self.prizeBox = _config.prizeBox;
			self.btnStart.addEventListener(annie.MouseEvent.CLICK, function () {
				if( self.isRunning ) return;
				self.ems.trigger("beforeLottery");
			});
			self.ems.on('beforeLottery',function(){
				myapp.beforeLottery(function (_prizeIndex) {
					self.lotteryIndex = self.getLotteryIndex(_prizeIndex);
					self.prizeIndex = _prizeIndex;
					self.ems.trigger("startLottery");
					self.isRunning = true;
				});
			});
			self.ems.on('startLottery', self.startLottery.bind(this));
			self.ems.on('endLottery', self.endLottery.bind(this));
		},
		getLotteryIndex: function (_prizeIndex){
			return _prizeIndex;
		},
		beforeLottery : function (cb) {
			console.log('beforeLottery');
		},
		startLottery : function (cb) {
			var self = this;
			var currFrame = 0, myst, mystTime = 80, mystRound = 0;
				
			function run() {
				myst = setTimeout(function () {
					if (currFrame == 10) {
						currFrame = 0;
						mystRound++;
						mystTime += (mystRound * 20)
					}
					self.prizeBox.gotoAndStop(++currFrame);
					if (mystRound == 4 && currFrame == self.lotteryIndex) {
						setTimeout(function () {
							self.ems.trigger('endLottery');
						}, 500);
						return;
					}
					run();
				}, mystTime);
			}
			run();
		},
		endLottery: function () {
			this.isRunning = false;
		}
	}