Hi!
Is it true that the example code below, using weak reference listener, works and the second below don´t (myButton is a global object)? If so, why?
[AS]
// Example code 1 - Working
private function setupMyButton():void
{
function myButtonEventHandler(event:MouseEvent):void
{
trace(“You clicked the button!”);
}
myButton.addEventListener(MouseEvent.CLICK, myButtonEventHandler, false, 0, true);
}
[/AS]
[AS]
// Example code 2 - Not working
private function setupMyButton():void
{
myButton.addEventListener(MouseEvent.CLICK, myButtonEventHandler, false, 0, true);
}
private function myButtonEventHandler(event:MouseEvent):void
{
trace(“You clicked the button!”);
}
[/AS]
But if removing the useWeakReference param the second code example will work:
[AS]
// Example code 2 - Working using a normal reference
private function setupMyButton():void
{
myButton.addEventListener(MouseEvent.CLICK, myButtonEventHandler);
}
private function myButtonEventHandler(event:MouseEvent):void
{
trace(“You clicked the button!”);
}
[/AS]