I tried doing this:
root.addEventListener(\"click\",
function ()
{
navigateToURL(ClickURLRequest,\"_self\");
});
And it
Here's a generic way of removing event listeners that i have used on production projects
addEventListener
(
Event.ACTIVATE,
function(event:Event):void
{
(event.target as EventDispatcher).removeEventListener(event.type, arguments.callee)
}
)
You can think of the function() keyword as a constructor, creating a new object (a closure) each time. Therefore, if you create the closure just for as a parameter and don't retain a reference anywhere, there's no way to get a hold of "the same" closure somewhere else.
The obvious solution is what you don't like, defining the function before using it. Of course, it can still be a full closure and not just a 'static-like' function. simply define it in the context you want, and assign it to a local variable.
I dont know what you're actually doing but in this particular example perhaps you could have a _clickEnabled global variable.
Then inside the event handler you just check _clickEnabled, and if its false you just return
immediately.
Then you can enable and disable the overall event without detaching and reattaching it.