understanding as3 custom events

understanding as3 custom events

ID:24325070

大小:55.00 KB

页数:4页

时间:2018-11-13

understanding as3 custom events_第1页
understanding as3 custom events_第2页
understanding as3 custom events_第3页
understanding as3 custom events_第4页
资源描述:

《understanding as3 custom events》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、UnderstandingAS3customevents  EveryAS3programmeruseseventlistenerstoalloouseclickorthebeginningofanee.  Noetoseehoesayitsnotadoitordiefeature.  Youcanalsomeif...then...elseandachievethesameresult,butfromaPROgrammerpointofvieorereadablethanaplexlistofc

2、onditionstocheckforevents.  Inthisscript,epassedlikeinUnderstandingAS3TimerClass,buteventtobetriggeredevery5seconds.  Obviouslyinthiscaseitsquitepointlesstocreateacustomevent,butIamshoport flash.display.Sprite; import flash.events.Event; import flash.

3、events.TimerEvent; import flash.utils.Timer; import flash.text.TextField; public class dispatch extends Sprite {  var dispatcher:time_dispatcher = nee_dispatcher();  var time_count:Timer=neer(1000);  var interval_timer:TextField = neer.x=5;   interval

4、_timer.y=5;   addChild(interval_timer);      time_count.addEventListener(TimerEvent.TIMER,shoe);   dispatcher.addEventListener(time_dispatcher.ON_DIV_BY_FIVE, on_event_triggered);   time_count.start();  }  private function on_event_triggered(event:Eve

5、nt):void {   interval_timer.text="TRIGGERED";  }  function shoe(event:TimerEvent) {   interval_timer.text=event.target.currentCount;   dispatcher.check_division(event.target.currentCount);  } }} import flash.events.EventDispatcher;import flash.events.

6、Event;class time_dispatcher extends EventDispatcher { public static var ON_DIV_BY_FIVE:String="can be divided"; public function check_division(num):void {  if (num%5==0) {   dispatchEvent(nee_dispatcher.ON_DIV_BY_FIVE));  } }}  Line8:Creatinganee_disp

7、atcherclass.Iincludedtheclassinthesamefiletomakethetutorialeasiertounderstand,butyoucanobviouslyhaveyourneesyntaxyouareusedexceptAS3doesnthaveanyON_DIV_BY_FIVElistener.  Theremaininglinesarequitethesameyouveseenathousandtimes,excludedline24berofelapse

8、dsecondscanbedividedby5.  Line35:Thisishowwefire,ordispatch,anevent.12下一页[感谢阅读这篇文章,..,]  AsIsaid,youcanalentbutinmyopinionacodeorereadablethansomethinglikeif(collected_items==total_itemstime_left>0){...  Thisistheresultofthescript:  本文示例源代码

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。