如何用< mx:SetEventHandler />删除EventListener? [英] Howto removeEventListener with <mx:SetEventHandler />?

查看:142
本文介绍了如何用< mx:SetEventHandler />删除EventListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除一个事件监听器(在这种情况下)一个Horizo​​ntalList。该列表使用属性初始化

I'm trying to remove an eventlistener on (in this specific case) a HorizontalList. The list is initialized with the property

itemRollOver =playPreview(event)

itemRollOver="playPreview(event)"

我想通过切换状态删除此事件监听器,并说明如下:

I'd like to remove this eventListener by switching state and stating something like:


< mx:SetEventHandler target ={horList} name =itemRollOverhandlerFunction =null/>

工作。事件仍处理,playPreview(event:ListEvent)仍然被调用。如何正确地做到这一点? (我知道我可以在Actionscript中做到这一点,但我特意想通过状态切换来实现)

This doesn't seem to work. The event is still handled and playPreview(event:ListEvent) is still called. How to properly do this? (I know I can do it in Actionscript, but I specifically want to do it by means of state switching)

Cheers Bart

Cheers Bart

推荐答案

AFAIK您只能删除添加了AS的侦听器,而不是添加了mxml的侦听器。所以你应该从mxml中删除监听器,在你的应用程序的creationComplete中使用AS来添加事件侦听器,然后无论你做什么来使你的状态切换都可以启动一个AS函数来删除它。

AFAIK you can only remove listeners that were added with AS, not ones added with mxml. So you should remove the listener from the mxml, on creationComplete of your app use AS to add the event listener, then whatever you do to cause your state to switch can fire an AS function to remove it.

我顶部的代码是这样的:

Of the top of my head the code is something like this:

HList.addEventListener(MOUSE_EVENT.RollOver,nameOfRollOverFunction);
HList.removeEventListener(MOUSE_EVENT.RollOver,nameOfRollOverFunction)

这篇关于如何用&lt; mx:SetEventHandler /&gt;删除EventListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆