10 Replies Latest reply on Feb 24, 2011 10:45 AM by GordonSmith

    Application "creationComplete" or "Initialize" ?

    kmcsekar Level 1

      Hi

       

      I want to create a chart component dynamically through action scripts at the time of application loading.  Which option is the best?

      CreationComplete  or  Initialize.

       

      Whats the difference between above 2?   Whats the difference in loading a component during initialization and after intialization(creation complete).

      Please revert back ASAP.

       

      Thanks!

        • 1. Re: Application "creationComplete" or "Initialize" ?
          leybniz Level 4

          safer in terms of null pointer exceptions is creationComplete

          • 2. Re: Application "creationComplete" or "Initialize" ?
            kmcsekar Level 1

            Thanks for your reply Alex.

            But the issue is,  I have a functionaity as follows,

             

            During Initialize, I create chart component.

            During creationComplete I create display object,  And I use chart.dataToLocal to transform data coordinate to pixel coordinate for attaching few display objects on top of chart.

             

            If I create chart component on creationcomplete as you suggested,  I don't get correct pixel values for Data Coordinate --> pixel Coordinate conversion.

             

            If I create the chart component on initialize and create displayobject on creationcomplete , I get the correct pixel values for Data Coordinate.

             

            So I will have to create the chart during initialization phase & display object during creation complete phase.

             

            How can I solve above issue as per your response?

            • 3. Re: Application "creationComplete" or "Initialize" ?
              Flex harUI Adobe Employee

              If you do something significant in your creationComplete handler, you are likely to cause something to call its invalidate*() methods and go through another pass of validating all the components.  If you use "initialize" you might have to worry about null pointers, but you won't cause another validation pass.

               

              We think of creationComplete as roughly equivalent to automatically clicking a button that runs some code (although it can delay the time before you see the application at startup.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              • 4. Re: Application "creationComplete" or "Initialize" ?
                leybniz Level 4

                hm, that's a completely different case, for your situation I'd recommend you to

                subclass your chart control as yourChartControl class and put all your external DisplayObjects logic inside that class,

                this may help

                • 5. Re: Application "creationComplete" or "Initialize" ?
                  kmcsekar Level 1

                  Thanks for you clarifiaction alex.  That answers when should I go for creation complete or intialize.

                   

                  But on creationComplete, it doesn't seem to work.  I have attached my sample POC for your reference.

                   

                  Please follow the

                  handleChange() method.

                   

                  I did what you said, called few invalidate*() methods after constructing the chart.  But the display objects are not placed correctly.

                   

                  Can you please try the POC I have attached and fix it appropriately.

                   

                  THAT WOULD BE A GREAT HELP AND THIS IS A CRUCIAL REQUIREMENT FOR US.

                  • 6. Re: Application "creationComplete" or "Initialize" ?
                    kmcsekar Level 1

                    Thanks for your response Alex.

                     

                    I just did what you said and the chart doesn't seem to be working properly.

                    My requirment is this

                     

                    Draw Chart + Draw Objects (line , VBox) on top of Chart.

                     

                    If I do both on creation complete,  Draw Chart is Successful.  But Draw Objects fails.

                     

                    I have attached my POC sample code.  can you please try this and fix it.

                     

                    THIS IS A VERY CRITICAL REQUIREMENT FOR US, AND WE ARE IN NEED OF SUPPORT FROM ADOBE.

                    • 7. Re: Application "Initialize" AND "creationComplete"!
                      leybniz Level 4

                      Let's see what we have here,

                       

                      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                      initialize="constructChart()"
                      creationComplete="handleChange()"
                      >

                        private function handleChange():void {
                          //constructChart();
                          var annElements:Array = new Array();
                          createSmithAnnotation();
                          createDeckerAnnotation();
                        }

                      your trouble is obvious - construct everything on initialize phase, use after creationComplete.

                      And I still insist that you create custom chart component out of your code, something like AnnotatableColumnChart.as

                      which will be capable to draw injected annotations. Good luck

                       

                      BTW: This thread could be renamed to "Initialize"  and (not or) "creationComplete"

                      • 8. Re: Application "creationComplete" or "Initialize" ?
                        Vishal Lad Level 1

                        hey hi,

                          

                        can u pls tel me why we use creationcomplete and initialize in flex...

                        am new to flex... please try 2 reply for this wit xplanation from d basic level....

                        awaiting for your reply

                         

                         

                        Thanks & Regards,

                        A.H

                        • 9. Re: Application "creationComplete" or "Initialize" ?
                          Vishal Lad Level 1

                          hey hi,

                            

                          can u pls tel me why we use creationcomplete and initialize in flex...

                          am new to flex... please try 2 reply for this wit xplanation from d basic level....

                          awaiting for your reply

                           

                           

                          Thanks & Regards,

                          A.H

                          • 10. Re: Application "creationComplete" or "Initialize" ?
                            GordonSmith Level 4

                            'preinitialize' - before children have been created

                             

                            'initialize' - after children have been created, but before they have been laid out

                             

                            'creationComplete' - after chidlren have been created and laid out

                             

                            If you need the x/y/width/height of all descendants to be correct, use creationComplete. Otherwise, use initialize. Modifying things in a creationComplete handler can cause another layout pass.

                             

                            Gordon Smith

                            Adobe Flex SDK Team