Howto removeEventListener with <mx:SetEventHandler />?

不想你离开。 提交于 2019-12-25 00:08:10

问题


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

itemRollOver="playPreview(event)"

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

<mx:SetEventHandler target="{horList}" name="itemRollOver" handlerFunction="null" />

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


回答1:


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)


来源:https://stackoverflow.com/questions/1973946/howto-removeeventlistener-with-mxseteventhandler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!