All,

Heres a little bit of code i knocked up to demonstrate.... For MXML - just extend the class and tie into the functions via the override.

On another note, you might want to check if the current object contains children - if so remove them before you remove yourself (via the removechild)


        public class UIComponentContainer extends Container
        {

                public var hasInit:Boolean = false;

                public function UIComponentContainer():void {
                        init();
                        addEventListener(Event.ADDED_TO_STAGE, bindEvents);
                        addEventListener(FlexEvent.REMOVE, unbindEvents);
                }
                
                public function init():void {
                        // does nothing !!      
                }

public function redraw(_isInit:Boolean = false, _abort:Boolean = false):void {
                        
                        if ((!_isInit) && ((!hasInit) || (_abort))) return;     
                                                                        
                        if (_isInit) hasInit = true;                    
                        // do something here !!

                }
                
                protected function bindEvents(_event:Event = null):void {
                        removeEventListener(Event.ADDED_TO_STAGE, bindEvents);
                        redraw(true);                                           
                }
                
                protected function unbindEvents(_event:FlexEvent = null):void {
                        removeEventListener(FlexEvent.REMOVE, unbindEvents);
                }

        }

Regards
Samuel

Im-At-Home BV
http://www.im-at-home.com

Overtoom 238-II / 1054HZ Amsterdam / The Netherlands
Tel: +31 20 750 8304 (Amsterdam, NL) / +1 646 385 7345 (Manhattan, US) / Mobile: +31 64 328 5922

Skype: samcolak / MSN: [EMAIL PROTECTED] / AIM: [EMAIL PROTECTED]

On Sep 23, 2008, at 7:25 PM, Samuel Colak wrote:

Ok - i did a bit of research....


you can do the following - trap for the notification FlexEvent.Remove which occurs when a child is removed
from a container. Other than that im not sure what else to do..

Basically trap this function... my own code already did something similar but this appears more accurate as the last
posted message......

Hope that helps some of you (by the way, the notification is raised by the Container
object under internal::removingChild function)

Regards,
Samuel


On Sep 23, 2008, at 5:52 PM, ozziegt wrote:

--- In [email protected], Tom Chiverton <[EMAIL PROTECTED]>
wrote:
>
>
> I normally use creationComplete for setting up the listeners.

I have been using creationComplete, but there is no way for me to
remove the listeners when the object is removed from the stage, which
leads to memory leaks.






Reply via email to