# useWeakReference-question

**URL:** <https://forum.kirupa.com/t/useweakreference-question/250074>\
**Category:** flash\
**Created:** [January 25, 2008, 6:26am UTC](https://forum.kirupa.com/t/useweakreference-question/250074 "2008-01-25T06:26:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunetics](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@lunetics](https://forum.kirupa.com/u/lunetics)\
**Post date:** [January 25, 2008, 6:26am UTC](https://forum.kirupa.com/t/useweakreference-question/250074/1 "2008-01-25T06:26:33Z")

</div>

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]
