Created
December 1, 2017 04:30
-
-
Save southill/16228a13eb8971547fb68ace0d577a13 to your computer and use it in GitHub Desktop.
MyLottery With Fla Frame Step
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment