Flash倒计时+写在自定义类+写在关键帧
生活随笔
收集整理的這篇文章主要介紹了
Flash倒计时+写在自定义类+写在关键帧
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
一、鏈接:
一、目的
1、因為很多都有倒計時圖片切換,所以我封裝一個倒計時的資源,以后直接從flash賦復制,交換一下資源就可以了
二、參考
1、AS3自定義事件以及發(fā)送事件(1)——發(fā)送事件
三、操作:寫在自定義類中:版本3.1
1、其余設置和版本3.1等類似
1、代碼:自定義類:My_countDown
1、關鍵幀中調(diào)用
三、操作:寫在自定義類中:版本3.1
1、項目設置
2、My_countDown 代碼
3、關鍵幀代碼:調(diào)用倒計時
三、操作:寫在自定義類中:版本2.0
1、項目設置
1、關鍵幀代碼:調(diào)用倒計時
1、?自定義類:My_countDown
三、操作:寫在關鍵幀中
1、項目設置
1、元件:數(shù)字:
1、元件: mc_time_task
1、配置文件:config-flash.xml
1、配置文件:關鍵幀代碼
1、倒計時:關鍵幀代碼
?
一、鏈接:
https://download.csdn.net/download/qq_40544338/12921178
一、目的
1、因為很多都有倒計時圖片切換,所以我封裝一個倒計時的資源,以后直接從flash賦復制,交換一下資源就可以了
?
二、參考
1、AS3自定義事件以及發(fā)送事件(1)——發(fā)送事件
https://blog.csdn.net/qq_40544338/article/details/108992347
- 總結(jié):知道自定義類發(fā)送消息給舞臺
?
三、操作:寫在自定義類中:版本3.1
1、其余設置和版本3.1等類似
1、代碼:自定義類:My_countDown
/**********************/ // 作者:xzy //功能:自定義類,讓舞臺添加物體,有開始、停止、重置定時器,最多實現(xiàn)3位倒計時 //日期:20201010 //版本:3.1 /**********************//* 完善: 版本3.2和3.1相比:添加了Clear函數(shù),對象移除添加的監(jiān)聽事件 版本3.1和3.0相比:添加初始化函數(shù)Init,不通過構造函數(shù)進行創(chuàng)建定時器,而是通過初始化函數(shù)Init 版本3.0和2.0相比:創(chuàng)建時候數(shù)字元件跳到傳遞來的數(shù)字。 */package MyLibrary {import flash.display.MovieClip;import flash.utils.Timer;import flash.events.TimerEvent;import flash.events.Event;public class My_countDown extends MovieClip{//發(fā)送監(jiān)聽事件static public const START:String = "START";static public const OVER:String = "OVER";//任務總時長,單位:秒public var timer_task_total:int = 0;//任務當前時間public var timer_task_current:int = 0;//定時器:任務public var timer_task:Timer = null;/*構造函數(shù):My_countDown*/public function My_countDown(){}public function Init(_total:int){timer_task_total = _total;Set_changeTime();//定時器:任務倒計時;if (timer_task==null){timer_task = new Timer(1000,timer_task_total);if (! timer_task.hasEventListener(TimerEvent.TIMER)){timer_task.addEventListener(TimerEvent.TIMER,TIMER_timer_task);}}}public function Clear(){//定時器:任務倒計時;if (timer_task!=null){timer_task.stop();if (timer_task.hasEventListener(TimerEvent.TIMER)){timer_task.removeEventListener(TimerEvent.TIMER,TIMER_timer_task);}timer_task = null;}}//定時器:任務倒計時public function TIMER_timer_task(e:TimerEvent){timer_task_current++;//trace("timer_task_current:"+timer_task_current);Set_changeTime();//倒計時結(jié)束:if (timer_task_current>=timer_task_total){timer_task.stop();//分發(fā)OVER事件;dispatchEvent(new Event(OVER));//新建事件傳入String參數(shù)}}//開始定時器public function Set_start(){timer_task.start();//分發(fā)START事件;dispatchEvent(new Event(START));//新建事件傳入String參數(shù)}//重置定時器public function Set_reset(){timer_task.reset();}//結(jié)束定時器public function Set_stop(){timer_task.stop();}/*功能:設置更換時間元件參數(shù):_showKind:顯示的種類,0:只顯示個位 1:顯示個位和十位 2:顯示個位、十位、百位*/public function Set_changeTime(){var currentTime:int = timer_task_total - timer_task_current;//百位var currentTime_baiWei:int = currentTime / 100;//十位var currentTime_shiWei:int = (currentTime - currentTime_baiWei * 100) / 10;//個位var currentTime_geWei:int = currentTime - currentTime_baiWei * 100 - currentTime_shiWei * 10;if (currentTime_baiWei==0){currentTime_baiWei = 10;}if (currentTime_shiWei==0){currentTime_shiWei = 10;}if (currentTime_geWei==0){currentTime_geWei = 10;}//this.mc_time_bai.gotoAndStop(currentTime_baiWei);this.mc_time_shi.gotoAndStop(currentTime_shiWei);this.mc_time_ge.gotoAndStop(currentTime_geWei);}}}1、關鍵幀中調(diào)用
創(chuàng)建
//任務倒計時 import MyLibrary.My_countDown;//創(chuàng)建:任務倒計時my_countDown.Init(timer_task_total);if (!my_countDown.hasEventListener(My_countDown.OVER)){my_countDown.addEventListener(My_countDown.OVER,OVER_my_countDown);}清除
?? ?//任務倒計時:移除添加的事件my_countDown.Clear();開啟定時器
//任務倒計時開始計時 my_countDown.Set_reset();my_countDown.Set_start();相應自定義類時間到了
//任務時間到了 function OVER_my_countDown(e:Event) {trace("任務時間到了!");Destroy_game();gotoAndStop("失敗"); }?
三、操作:寫在自定義類中:版本3.1
1、項目設置
2、My_countDown 代碼
/**********************/ // 作者:xzy //功能:自定義類,讓舞臺添加物體,有開始、停止、重置定時器,最多實現(xiàn)3位倒計時 //日期:20201010 //版本:3.1 /**********************//* 完善: 版本3.1和3.0相比:添加初始化函數(shù)Init,不通過構造函數(shù)進行創(chuàng)建定時器,而是通過初始化函數(shù)Init 版本3.0和2.0相比:創(chuàng)建時候數(shù)字元件跳到傳遞來的數(shù)字。 */package MyLibrary {import flash.display.MovieClip;import flash.utils.Timer;import flash.events.TimerEvent;import flash.events.Event;public class My_countDown extends MovieClip{//發(fā)送監(jiān)聽事件static public const START:String = "START";static public const OVER:String = "OVER";//任務總時長,單位:秒public var timer_task_total:int = 0;//任務當前時間public var timer_task_current:int = 0;//定時器:任務public var timer_task:Timer = null;/*構造函數(shù):My_countDown*/public function My_countDown(){//timer_task_total = _total;////Set_changeTime();//定時器:任務倒計時;//if (timer_task==null)//{//timer_task = new Timer(1000,timer_task_total);//if (! timer_task.hasEventListener(TimerEvent.TIMER))//{//timer_task.addEventListener(TimerEvent.TIMER,TIMER_timer_task);//}//}}public function Init(_total:int){timer_task_total = _total;Set_changeTime();//定時器:任務倒計時;if (timer_task==null){timer_task = new Timer(1000,timer_task_total);if (! timer_task.hasEventListener(TimerEvent.TIMER)){timer_task.addEventListener(TimerEvent.TIMER,TIMER_timer_task);}}}//定時器:任務倒計時public function TIMER_timer_task(e:TimerEvent){timer_task_current++;//trace("timer_task_current:"+timer_task_current);Set_changeTime();//倒計時結(jié)束:if (timer_task_current>=timer_task_total){timer_task.stop();//分發(fā)OVER事件;dispatchEvent(new Event(OVER));//新建事件傳入String參數(shù)}}//開始定時器public function Set_start(){timer_task.start();//分發(fā)START事件;dispatchEvent(new Event(START));//新建事件傳入String參數(shù)}//重置定時器public function Set_reset(){timer_task.reset();}//結(jié)束定時器public function Set_stop(){timer_task.stop();}/*功能:設置更換時間元件參數(shù):_showKind:顯示的種類,0:只顯示個位 1:顯示個位和十位 2:顯示個位、十位、百位*/public function Set_changeTime(){var currentTime:int = timer_task_total - timer_task_current;//百位var currentTime_baiWei:int = currentTime / 100;//十位var currentTime_shiWei:int = (currentTime - currentTime_baiWei * 100) / 10;//個位var currentTime_geWei:int = currentTime - currentTime_baiWei * 100 - currentTime_shiWei * 10;if (currentTime_baiWei==0){currentTime_baiWei = 10;}if (currentTime_shiWei==0){currentTime_shiWei = 10;}if (currentTime_geWei==0){currentTime_geWei = 10;}//this.mc_time_bai.gotoAndStop(currentTime_baiWei);this.mc_time_shi.gotoAndStop(currentTime_shiWei);this.mc_time_ge.gotoAndStop(currentTime_geWei);}}}?
?
3、關鍵幀代碼:調(diào)用倒計時
import MyLibrary.My_countDown;stop();Start_countDown();//功能:初始化 function Start_countDown() {//創(chuàng)建:任務倒計時 my_countDown.Init(timer_task_total);//任務倒計時開始計時my_countDown.Set_start();}//功能:離開此場景,需要移除的東西; function Destroy_countDown() {}?
三、操作:寫在自定義類中:版本2.0
1、項目設置
1、關鍵幀代碼:調(diào)用倒計時
import MyLibrary.My_countDown;var my_countDown:My_countDown = null;stop();Start_countDown();//功能:初始化 function Start_countDown() {//初始化:倒計時Init_countDown(); }//功能:離開此場景,需要移除的東西; function Destroy_countDown() {//移除 :任務倒計時if (my_countDown!=null){if (my_countDown.hasEventListener(My_countDown.START)){my_countDown.removeEventListener(My_countDown.START,START_countDown);}if (my_countDown.hasEventListener(My_countDown.OVER)){my_countDown.removeEventListener(My_countDown.OVER,OVER_countDown);}if (stage.contains(my_countDown)){stage.removeChild(my_countDown);}} }//初始化:倒計時 function Init_countDown() {//初始化:任務倒計時if (my_countDown==null){my_countDown = new My_countDown(2);//倒計時幾秒//添加監(jiān)聽事件if (! my_countDown.hasEventListener(My_countDown.START)){my_countDown.addEventListener(My_countDown.START,START_countDown);}if (! my_countDown.hasEventListener(My_countDown.OVER)){my_countDown.addEventListener(My_countDown.OVER,OVER_countDown);}if (! stage.contains(my_countDown)){stage.addChild(my_countDown);}}my_countDown.Set_start(); }function START_countDown(e:Event):void {trace(e);//(2) }function OVER_countDown(e:Event):void {trace(e);//(4) }1、?自定義類:My_countDown
/**********************/ // 作者:xzy //功能:自定義類,讓舞臺添加物體,有開始、停止、重置定時器,最多實現(xiàn)3位倒計時 //日期:20201010 //版本:2.0 /**********************/ package MyLibrary {import flash.display.MovieClip;import flash.utils.Timer;import flash.events.TimerEvent;import flash.events.Event;public class My_countDown extends MovieClip{//發(fā)送監(jiān)聽事件static public const START:String = "START";static public const OVER:String = "OVER";//任務總時長,單位:秒public var timer_task_total:int = 0;//任務當前時間public var timer_task_current:int = 0;//定時器:任務public var timer_task:Timer = null;public function My_countDown(_total:int){timer_task_total = _total;//倒計時原件暫停this.mc_time_bai.gotoAndStop(1);this.mc_time_shi.gotoAndStop(1);this.mc_time_ge.gotoAndStop(1);//定時器:任務倒計時;if (timer_task==null){timer_task = new Timer(1000,timer_task_total);if (! timer_task.hasEventListener(TimerEvent.TIMER)){timer_task.addEventListener(TimerEvent.TIMER,TIMER_timer_task);}}}//定時器:任務倒計時public function TIMER_timer_task(e:TimerEvent){timer_task_current++;trace("timer_task_current:"+timer_task_current);Set_changeTime();//倒計時結(jié)束:if (timer_task_current>=timer_task_total){timer_task.stop();//分發(fā)OVER事件;dispatchEvent(new Event(OVER));//新建事件傳入String參數(shù)}}//開始定時器public function Set_start(){timer_task.start();//分發(fā)START事件;dispatchEvent(new Event(START));//新建事件傳入String參數(shù)}//重置定時器public function Set_reset(){timer_task.reset();}//結(jié)束定時器public function Set_stop(){timer_task.stop();}//設置更換時間public function Set_changeTime(){var currentTime:int = timer_task_total - timer_task_current;//百位var currentTime_baiWei:int = currentTime / 100;//十位var currentTime_shiWei:int = (currentTime - currentTime_baiWei * 100) / 10;//個位var currentTime_geWei:int = currentTime - currentTime_baiWei * 100 - currentTime_shiWei * 10;if (currentTime_baiWei==0){currentTime_baiWei = 10;}if (currentTime_shiWei==0){currentTime_shiWei = 10;}if (currentTime_geWei==0){currentTime_geWei = 10;}this.mc_time_bai.gotoAndStop(currentTime_baiWei);this.mc_time_shi.gotoAndStop(currentTime_shiWei);this.mc_time_ge.gotoAndStop(currentTime_geWei);}}}?
三、操作:寫在關鍵幀中
1、項目設置
1、元件:數(shù)字:
1-9幀對應1-9圖片,10幀是0圖片
1、元件: mc_time_task
1、配置文件:config-flash.xml
<Config><Time><timer_task_total>5</timer_task_total> <!--任務總時長,單位:秒--></Time> </Config>1、配置文件:關鍵幀代碼
import flash.net.URLRequest; import flash.net.URLLoader;fscommand("fullscreen","true");stop();//任務總時長,單位:秒 var timer_task_total:int=0; var timer_task_current:int = 0; var timer_task:Timer=null;//獲取一個xml文件 var url:URLRequest = null; //使用URLLoader導入數(shù)據(jù) var loadurl:URLLoader = null;Start_config();//功能:初始化 function Start_config() {if (url==null){url = new URLRequest("config-flash.xml");}if (loadurl==null){loadurl = new URLLoader(url);}//添加事件******,以在XML數(shù)據(jù)導入完成后處理XML數(shù)據(jù);if (! loadurl.hasEventListener(Event.COMPLETE)){loadurl.addEventListener(Event.COMPLETE,Loadxml);} }//功能:離開此場景,需要移除的東西 function Destroy_config() { }//功能:讀取配置文件 function Loadxml(event:Event) { var xml:XML = XML(loadurl.data);//導入完成后,使用導入的數(shù)據(jù)創(chuàng)建XML對象timer_task_total = xml.Time.timer_task_total;trace("timer_task_total:"+timer_task_total);Destroy_config();gotoAndStop("倒計時"); }1、倒計時:關鍵幀代碼
stop();Start_countDown();//功能:初始化 function Start_countDown() {//初始化:倒計時Init_countDown(); }//功能:離開此場景,需要移除的東西; function Destroy_countDown() {//移除:任務倒計時timer_task.stop();if (timer_task.hasEventListener(TimerEvent.TIMER)){timer_task.removeEventListener(TimerEvent.TIMER,TIMER_timer_task);timer_task = null;} }//初始化:倒計時 function Init_countDown() {mc_time_task.mc_time_bai.stop();mc_time_task.mc_time_shi.stop();mc_time_task.mc_time_ge.stop();//定時器:任務倒計時if (timer_task==null){timer_task = new Timer(1000,timer_task_total);if (! timer_task.hasEventListener(TimerEvent.TIMER)){timer_task.addEventListener(TimerEvent.TIMER,TIMER_timer_task);}}timer_task.start(); }//定時器:任務倒計時 function TIMER_timer_task(e:TimerEvent) {timer_task_current++;trace("timer_task_current:"+timer_task_current);ShowTime();if (timer_task_current>=timer_task_total){timer_task.stop();trace("游戲結(jié)束");} }//顯示時間 function ShowTime() {var currentTime:int = timer_task_total - timer_task_current;//百位var currentTime_baiWei:int = currentTime / 100;//十位var currentTime_shiWei:int = (currentTime - currentTime_baiWei * 100) / 10;//個位var currentTime_geWei:int = currentTime - currentTime_baiWei * 100 - currentTime_shiWei * 10;if (currentTime_baiWei==0){currentTime_baiWei = 10;}if (currentTime_shiWei==0){currentTime_shiWei = 10;}if (currentTime_geWei==0){currentTime_geWei = 10;}mc_time_task.mc_time_bai.gotoAndStop(currentTime_baiWei);mc_time_task.mc_time_shi.gotoAndStop(currentTime_shiWei);mc_time_task.mc_time_ge.gotoAndStop(currentTime_geWei);}?
總結(jié)
以上是生活随笔為你收集整理的Flash倒计时+写在自定义类+写在关键帧的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java毕业设计HTML5旅游网站源码+
- 下一篇: java 旅游网站项目实现_基于jsp的