2016-10-13 00:16:48 点击量:11 标签: 收藏本文
这是一个非常有用的倒计时类,常用于游戏当中,用于检测时间的倒计时
倒计时类:
- import mx.events.EventDispatcher;
- import mx.utils.Delegate;
- //倒计时
- class game.time.Time {
- private var _id:Number;
- private var _second:Number;
- private var _total:Number;
- private var dispatchEvent:Function;
- public var addEventListener:Function;
- public var removeEventListener:Function;
- public function Time(s) {
- EventDispatcher.initialize(this);
- _second = s;
- _total = s;
- }
- public function getTime() {
- return _second;
- }
- private function timeing() {
- if (_second>0) {
- _second--;
- this.dispatchEvent({type:"onPlay", value:_second});
- } else {
- this.dispatchEvent({type:"onStop", value:_second});
- trace("stop")
- this.stop();
- }
- }
- public function play() {
- _id = setInterval(Delegate.create(this, timeing), 1000);
- }
- public function stop() {
- _second = _total;
- clearInterval(_id);
- }
- }
使用代码:
- import game.time.Time;
- //倒计时的时间
- var _totalTime = 30;
- var _time = new Time(_totalTime);
- _time.addEventListener("onPlay", timeStart);
- _time.addEventListener("onStop", timeOver);
- //计时中..
- function timeStart(obj) {
- time = obj.value;
- score = _score;
- update();
- }
- //超时,结束游戏
- function timeOver() {
- gotoAndStop("over");
- }
- startBtn.onRelease=function(){
- //启动倒计时
- _time.play()
- }
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室