Basically I have this function:
private function clickURL(url:String):Function{
trace("Function has been instantiated");
return function(event:MouseEvent):void{
trace("Function has been run");
ExternalNavigation.newBrowserWindow(url);
}
}
The purpose of this function is to take an url, put the url in another function and pass that function back so I can just type:
urlButton.addEventListener(MouseEvent.CLICK, clickURL("http://test.com"));
The function clickURL will return the function with the event parameter back to the addEventListener function. In that way I specify what url which will be opened when you press the button.
Here's the output of what happens when you use it:
//Function has been instantiated
The internatl function never gets run when you click the button. So I thought I'd try it out with a fake event to be sure I didn't miss anything.
var clickTest:Function = clickURL("http://stackoverflow.com");
clickTest(new MouseEvent(MouseEvent.CLICK));
Here's the output:
//Function has been instantiated
//Function has been run
As you can see, both functions are run. Have anyone got an idea to why this is working and not with the addEventListener?
Regards Z