> Therefore there will always be a reference to the object and GC would
not collect it.

I think you misunderstand. When you write
 
    <mx:Button id="myButton" click="onClick"/>
 
you cause the Button instance (the dispatcher of the 'click' event) to
have a reference to the Application instance (the listener for the
'click' event) and not the other way around. A dispatcher keeps a list
of listeners, but listeners do not remember the dispatcher that they
registered with.
 
If you were to do
 
    removeChild(myButton);
    myButton = null;
 
the Button would be eligible for garbage-collection because the
Application would no longer have any reference to it.
 
But I doubt that you're dynamically removing components, so what kind of
leak were you worried about anyway?
 
- Gordon
 
________________________________

From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of Firdosh Tangri
Sent: Friday, September 14, 2007 3:32 PM
To: [email protected]
Subject: Re: [flexcomponents] Removing Events defined by MXML





Well because the callback function keeps getting called even when I try
to remove the
event listener 

<mx:Application>
     <mx:Script>
        <![CDATA[
                  private function onClick():void{ 
                        
                       trace("click");
                       myButton.removeEventListener(MouseEvent.CLICK ,
onClick);
 
                  }

         ]]>
        </mx:Script> 
       
        <mx:Button id="myButton" click="onClick" />
</mx:Application>

In the above example the onClick function keeps getting called and the 

myButton.removeEventListener (MouseEvent.CLICK , onClick); 

does not work.

Therefore there will always be a reference to the object and GC would
not collect it.

cheers
firdosh



On 9/14/07, Gordon Smith <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> >
wrote: 

        

        I just want to mention... 
         
        The name of the autogenerated event handler method for an MXML
event attribute is an undocumented implementation detail that is subject
to change without notice in future versions of Flex.
         
        Also, I'm curious what you're trying to accomplish by removing
these listeners.
         
        - Gordon

________________________________

        From: [email protected]
<mailto:[email protected]>
[mailto:[email protected] <mailto:[EMAIL PROTECTED]> ] On
Behalf Of Firdosh Tangri
        Sent: Friday, September 14, 2007 9:20 AM
        To: [email protected]
<mailto:[email protected]> 
        Subject: Re: [flexcomponents] Removing Events defined by MXML
        
        
        

        Hey Josh,
                       thanks well I an working on a big project and a
lot of creation complete and other mxml defined events are there
        
        I used a hack to kill the eventlistener 
        
        basically just did  a 
        
        var comp:UIComponent = event.currentTarget as UIComponent;
        comp.removeEventListener(MouseEvent.CLICK,
Application.application["__btn_click"];
        
        so there is 2 underscore , the id of the component in this case
"btn" and then underscore again and then the event name , which is click
here 
        
        
        and that basically took care of the problem.
        
        cheers
        firdosh
        
        
        

        On 9/14/07, Josh Tynjala <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote: 

                As far as I know, it's not possible to remove events of
this type. The Flex compiler actually generates a function to wrap
around whatever you call. You can see the exact code if you look at the
generated code using the -keep compiler argument, but it looks something
like this:
                
                private function
someGeneratedFunctionName(event:MouseEvent):void
                {
                    //your code gets copied here
                    onClick();
                }
                
                You can get an idea of why when you think of the fact
that the "event" parameter is available in your click="" attribute in
the MXML. You can either pass it to your function or ignore it
completely. In ActionScript, when you use addEventListener instead, your
function must always accept an event parameter.

                
                
                Firdosh Tangri wrote: 

                        hey all,
                                    I was just wondering if i define an
event by mxml like
                        <mx:Button id="myBtn" click="onClick();") />
                        
                        and then try and remove it
                        
                        private function onClick():void{ 
                            trace("Click");
                            myBtn.removeEventListener(MouseEvent.CLICK,
onClick);
                        }
                        
                        it still keeps calling the function but if i add
the event listener through as
                        
                        like 
                        
                        myBtn.addEventListener (MouseEvent.CLICK ,
onClick);
                        
                        then it removes the call back function.
                        
                        thanks
                        cheers
                        firdosh
                        
                        
                        
                        


                

                


        

        

        

        


 

Reply via email to