<?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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。