RemoveEventListener无法移除事件监听器的情况
2009-10-19 22:30
393 查看
小杜前几天问了我一个很基础的问题,居然就被问住了。
为什么removeEventListener不起效果,查了一下,原来对于MXML的属性中定义的事件监听无法用removeEventListener来移除的。以前看书居然没有看到,罪过罪过。
In the example
below flex removeEventListener method working is
demonstrated. This method removes the events from the flex components. Here
mouse click event are removed by the method. In the example method doesn't able
to remove the event from the button with id b3
because on this flex control, the associated event is built with the button
click attribute.
And this button control tag is under mxml tags, this shows
that events cannot be removed that are added inside the mxml tags.
为什么removeEventListener不起效果,查了一下,原来对于MXML的属性中定义的事件监听无法用removeEventListener来移除的。以前看书居然没有看到,罪过罪过。
In the example
below flex removeEventListener method working is
demonstrated. This method removes the events from the flex components. Here
mouse click event are removed by the method. In the example method doesn't able
to remove the event from the button with id b3
because on this flex control, the associated event is built with the button
click attribute.
And this button control tag is under mxml tags, this shows
that events cannot be removed that are added inside the mxml tags.
<?xml version = '1.0' encoding = 'utf-8'?> <mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml' initialize = 'addEvent();'> <mx:Script> import mx.controls.Alert; public function addEvent():void{ b1.addEventListener(MouseEvent.CLICK, alertbox, false, 0); } public function removeEvent():void{ b1.removeEventListener(MouseEvent.CLICK, alertbox); b2.removeEventListener(MouseEvent.CLICK, alertbox); b3.removeEventListener(MouseEvent.CLICK, alertbox); } public function alertbox(event:Event):void{ Alert.show('Mouse click event occured'); } </mx:Script> <mx:HBox> <mx:Button id = 'b1' label = 'b1 button'/> <mx:Button id = 'b2' label = 'b2 button' initialize = 'b2.addEventListener(MouseEvent.CLICK, alertbox, false,0);'/> <mx:Button id = 'b3' label = 'b3 button' click = 'alertbox(event);'/> </mx:HBox> <mx:TextInput text = 'click to remove click action' click = 'removeEvent()' editable = 'false'/> </mx:Application>
相关文章推荐
- removeEventListener 移除已知对象的特定绑定事件的所有function
- 百度地图,移除添加的事件(addEventListener,removeEventListener)
- js添加事件和移除事件:addEventListener()与removeEventListener()
- 事件监听(addEventListener())及其移除(removeEventListener)
- 监听事件绑定(addEventListener、attachEvent)和移除(removeEventListener、detachEvent)
- JS事件---DOM2级事件处理:addEventListener()、removeEventListener()、attachEvent()
- spark学习-48-Spark的event事件监听器LiveListenerBus和特质SparkListenerBus以及特质ListenerBus
- js使用getEventListeners移除事件监听器
- js高级程序设计笔记之-addEventListener()与removeEventListener(),事件解除与绑定
- JS事件处理(removeEventListener addEventListener)
- 兼容8事件绑定与解绑addEventListener、removeEventListener和ie的attachEvent、detachEvent
- 与事件处理相关的function:addEventListener、removeEventListener与attachEvent、detachEvent
- javascript事件绑定,取消,addEventListener,removeEventListener,attachEvent,detachEvent
- flex removeEventListener MDIWINDOW 移除 timer
- 事件监听函数:addEventListener() removeEventListener()
- js中事件的绑定与解绑:attachEvent/detachEvent、addEventListener/removeEventListener
- js 添加_删除事件 addEventListener/removeEventListener和attachEvent/detachEvent
- JS添加事件和解绑事件:addEventListener()与removeEventListener()
- JS添加事件和解绑事件:addEventListener()与removeEventListener()
- js玩具——UI组件:PropertyChangeEventListener 属性改变事件监听器及默认实现