ActionScript 3.0 using closures for event handlers

前端 未结 9 2050
挽巷
挽巷 2020-12-28 18:35

I tried doing this:

root.addEventListener(\"click\", 
   function () 
   { 
      navigateToURL(ClickURLRequest,\"_self\"); 
   });

And it

9条回答
  •  旧巷少年郎
    2020-12-28 19:23

    It's not too much different than using a defined function, but maybe this will satisfy your needs. Remember that Functions are first-class objects in ActionScript and you can store and pass them around as variables.

    protected function addListener()
    {
        m_handler = function(in_event:Event) { removeEventListener(MouseEvent.CLICK, m_handler); m_handler=null}
        addEventListener(MouseEvent.CLICK, m_handler)
    }
    protected var m_handler:Function
    

提交回复
热议问题