views:

118

answers:

3

Dear friends, I am confused about the order of systen events. As per the book, 'childAdd' event of parentcontainer should be triggered after triggering of 'PreInitialize' and 'Initialize' event of childcontianer while as per the program out put it seems otherwise. Please help.

What I found in books is as below:

\ Container----------Component

Preinitialize

------------------Preinitialize

------------------Ininitialize

childAdd

Initialize

------------------creationComplete

------------------updateComplete

creationComplete

updateComplete

===========================================================================================

While what I tried myself is as below. These are the o/p of trace statements which were printed in respective event handlers.

Preinitialize in Application

CreateChildren in Application

----------------Constructor of MyContainer

childAdd in Application

----------------PreInitialize MyContainer

----------------CreateChildren MyContainer

--------------------------------Constructor ChildContainer

----------------childAdd MyContainer

-------------------------------PreInitialize ChildContainer

-------------------------------CreateChildren ChildContainer

-------------------------------Initialize ChildContainer

----------------Initialize MyContainer

Please find the code below:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  layout="vertical"
 xmlns:local= "*" childAdd="handleChildAddApp()" initialize="handleInitializeApp)"
 preinitialize="handlePreinitializeApp()"> 
     <local:MyClass id="MyContainer" preinitialize="handlePreinitializeOuter()" childAdd="handleChildAddOuter()" initialize="handleInitializeOuter()" title="Outer">
         <local:MyPanel id="ChildContainer" preinitialize="handlePreinitializeInner()" initialize="handleInitializeInner()" />
     </local:MyClass>
     <mx:Script>
    <![CDATA[

        public function handlePreinitializeApp():void {

            trace('Preinitialize in Application');

        }


        override protected function createChildren():void {

            trace( "CreateChildren in Application" );

            super.createChildren();

        }


        public function handleChildAddApp():void{

            trace('childAdd in Application');

        }


        public function handleInitializeApp():void{

            trace('Initialize Application');

        }


        public function handleCreationCompleteApp():void{

            trace('CreateChildren in Application');

        }

        public function handlePreinitializeOuter():void{

            trace('PreInitialize MyContainer');

        }


        public function handleChildAddOuter():void{

            trace('childAdd MyContainer');

        }

        public function handleInitializeOuter():void{

            trace('Initialize MyContainer');



        }

        public function handlePreinitializeInner():void{

            trace('PreInitialize ChildContainer');

        }


        public function handleInitializeInner():void{

            trace('Initialize ChildContainer');

        }


    ]]>

</mx:Script>

Thanks in advance.

A: 

Basic documentation:

http://www.adobe.com/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=containers_intro_063_12.html

http://unitedmindset.com/jonbcampos/2009/02/12/deferred-component-instantiation-in-actionscript/

http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_04.html

What you might be running into is "deferred creation policy". Check the above links, and look into creationPolicy="all".

eruciform
@ashine: did creationPolicy fix it for you?
eruciform
+1  A: 

It's hard to tell from your trace statements how your code is structured and I'm not entirely clear on your question, but here is a nice chart showing the flow of events for the component life cycle that I've used often: http://danorlando.com/?p=122 Hope that helps.

Wade Mueller
Thans for the help Wade. Thats a really nice chart.But my question is still answered. Why childAdd of parent is called before 'preinitialize' and 'initialize' of child component in my code ?
Ashine
A: 

I'm not going to point fingers, but what I will say is that there may be some confusion somewhere.

Remember that there are two adding children events: childAdd, childAdded

One that is prior to the child's lifecycle startup, and one that is after. Make sure that you are looking for the event that you are expecting.

jonbcampos