资源描述:
《flash事件侦听器基础》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、FLASH事件侦听器基础TheFlasheventlistenerbaseeventlistenerbaseActionscripteventhandlerforatotaloftwoclasses:theeventhandlermethodandeventlistenet,tounderstandtheconceptofeventlistener,youmustfirstunderstandthediffereneebetweenlinearprogrammingandevent-drivenprogramming;Aprogrammingmethodcomparison(1)ontheba
2、sisoftimeprogrammingsimilartoobservewhetherapotofwatertoboilandwanttoknowifwaterhasbeenboiling,needtoconstantlytoobserve,infactwearedoingsointhepast;Forexample:Themovieclipmanisaman,andthemovieclipsthewaterbottleforthekettle;Thevariabletemperatureisthetemperature:Whenthewatertemperatureis100degrees,
3、peoplecantakethewateraway.Theprogramisplacedasfollowsonthefirstframeoftheroottimeline;This.onenterframe=function(){If(waterbottle・Temperature=二100)This・Man.Takewater();}}Thefilmclipmanconstantlymonitorsachangeinthemovieclip,andtakesitawaywhenavariableis100.(2)event-drivenprogramming;Event-drivenprog
4、rammingonthecontrary,theconceptofthepastbymonitoringmustnowbecomeamessagesender,nowmanyofthekettlehasapeakdetector,whenthewaterisboilingwillbark,movieclipmandon'tneedtoconstantlymonitorthewater,aslongasthebeepdevice(radio)bark(radio),awatchdog(thelistener)canreceivethebroadcasts,andthentotakewater;T
5、oenablemantolistentothesoundofthewaterbottle,hemustregisterthemovieclipmanasalistenerforthewaterbottleevent;//registeralistenerobjectmanforthebroadcastobjectwaterbottle・This.Sowhenthewateropens,thewaterbottlenotifiestheregisteredobject,man,thatthewaterisboiling;Afterreceivingthenotification,themovie
6、clipmangoesandtakesthewateraway.//defineaneventhandlermethod;This.onwateTbottletempeTatuTe二function(ss){・・・This.Man.Takewater(ss);ThesecondeventlistenermodelWordmeaning;ListenerObject//listenerobject(receiver);Broadcastobject//broadcastobject(broadcaster);ThestandardmodelListenerobject・Eventname二fun
7、ction(){・・・}Broadcastobject・AddListener(listenerobject);Name1y;Listenerobject・eventname二function(){・・・};Broadcastobject・AddListener(listenerObject);instructionsThelistenerobjectlistenerObjectcanbeanyo