加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex_添加、移除事件监听器示例;

发布时间:2020-12-15 05:10:24 所属栏目:百科 来源:网络整理
导读:?xml version="1.0" encoding="utf-8"? s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" ?? ??? ??? ??? xmlns:s="library://ns.adobe.com/flex/spark" ?? ??? ??? ??? xmlns:mx="library://ns.adobe.com/flex/mx" ?? ??? ??? ??? minWidth="1024"
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" ?? ??? ??? ??? xmlns:s="library://ns.adobe.com/flex/spark" ?? ??? ??? ??? xmlns:mx="library://ns.adobe.com/flex/mx" ?? ??? ??? ??? minWidth="1024" minHeight="768" pageTitle="TheStudioOfCenyebao"> ?? ? ?? ?<!-- Demo_添加、移除事件监听器示例 --> ?? ? ?? ?<fx:Declarations> ?? ??? ? ?? ?</fx:Declarations> ?? ? ?? ?<fx:Script> ?? ??? ?<![CDATA[ ?? ??? ??? ?/** ?? ??? ??? ? * 添加、移除监听器; ?? ??? ??? ? */ ?? ??? ??? ?protected function toggleListeners():void{ ?? ??? ??? ??? ?if(rectBox.hasEventListener(MouseEvent.CLICK)) { ?? ??? ??? ??? ??? ?log("=>移除事件监听器"); ?? ??? ??? ??? ??? ?rectBox.removeEventListener(MouseEvent.MOUSE_OVER,onEvent); ?? ??? ??? ??? ??? ?rectBox.removeEventListener(MouseEvent.MOUSE_OUT,onEvent); ?? ??? ??? ??? ??? ?rectBox.removeEventListener(MouseEvent.MOUSE_MOVE,onEvent); ?? ??? ??? ??? ??? ?rectBox.removeEventListener(MouseEvent.CLICK,onEvent); ?? ??? ??? ??? ?}else { ?? ??? ??? ??? ??? ?log("=>添加事件监听器"); ?? ??? ??? ??? ??? ?rectBox.addEventListener(MouseEvent.MOUSE_OVER,onEvent); ?? ??? ??? ??? ??? ?rectBox.addEventListener(MouseEvent.MOUSE_OUT,onEvent); ?? ??? ??? ??? ??? ?rectBox.addEventListener(MouseEvent.MOUSE_MOVE,onEvent); ?? ??? ??? ??? ??? ?rectBox.addEventListener(MouseEvent.CLICK,onEvent); ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?/** ?? ??? ??? ? * 打印日志; ?? ??? ??? ? */ ?? ??? ??? ?protected function log(logStr:String):void{ ?? ??? ??? ??? ?outfield.text = logStr + "n" + outfield.text; ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?/** ?? ??? ??? ? * 事件触发的函数; ?? ??? ??? ? */ ?? ??? ??? ?protected function onEvent(event:Event):void{ ?? ??? ??? ??? ?log("事件类型:" + event.type); ?? ??? ??? ?} ?? ??? ?]]> ?? ?</fx:Script> ?? ? ?? ?<!--view--> ?? ?<s:VGroup verticalCenter="0" horizontalCenter="0" width="300" height="350"> ?? ??? ?<s:HGroup width="100%" height="100" verticalAlign="bottom"> ?? ??? ??? ?<s:Group id="rectBox" width="175" height="100%"> ?? ??? ??? ??? ?<s:Rect width="100%" height="100%"> ?? ??? ??? ??? ??? ?<s:fill> ?? ??? ??? ??? ??? ??? ?<s:SolidColor color="0x979797"/> ?? ??? ??? ??? ??? ?</s:fill> ?? ??? ??? ??? ?</s:Rect> ?? ??? ??? ?</s:Group> ?? ??? ??? ?<s:Button id="toggleBtn" label="ToggleListeners" click="toggleListeners()"/> ?? ??? ?</s:HGroup> ?? ??? ?<s:TextArea id="outfield" width="100%" height="100%"/> ?? ?</s:VGroup> </s:Application>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读