7 Replies Latest reply on Nov 12, 2008 1:18 PM by Newsgroup_User

    Help Understanding Event Model

    rss181919
      I am having trouble getting items initialized ontime. I have read the flex 3 development guide and some other docunentation a couple of times and i have read other posts on this forum concerning the creationComplete event. I still don't have a clear picture of how this works.

      The development guide says the following:
      initialize - Dispatched when a component and all its children have been created, but before the component size has
      been determined.
      creationComplete - Dispatched when the component has been laid out and the component is visible (if appropriate).

      From this, I am assuming that using a creationComplete event for a parent object should have access to any component ids on child objects.

      However, this is not happening in my code.
      I have the following scenario:
      Container1
      ->Container2 (child of Container1)
      -->Datagrid (child of Container2)

      In container 1, I attempt to register an event listener with the itemClick event of the datagrid using the creationComplete event. This fails. However, if I move this registration to a click event on Container 1, it is successful. So the problem appears to be related to instantiation of the datagrid. So why would the dataGrid not be instantiated by the time the Container1 creationComplete event fires?

        • 1. Re: Help Understanding Event Model
          Level 7

          "rss181919" <webforumsuser@macromedia.com> wrote in message
          news:gfeqai$gr6$1@forums.macromedia.com...
          >I am having trouble getting items initialized ontime. I have read the flex
          >3
          > development guide and some other docunentation a couple of times and i
          > have
          > read other posts on this forum concerning the creationComplete event. I
          > still
          > don't have a clear picture of how this works.
          >
          > The development guide says the following:
          > initialize - Dispatched when a component and all its children have been
          > created, but before the component size has
          > been determined.
          > creationComplete - Dispatched when the component has been laid out and the
          > component is visible (if appropriate).

          A lot of this depends. For instance, if Container1 is a ViewStack or if
          Container2 is added via addChild, Container2 might or might exist at
          creationComplete of Container1. All bets are off on creation of children of
          Container2 at creationComplete of Container1 :-).

          > From this, I am assuming that using a creationComplete event for a parent
          > object should have access to any component ids on child objects.
          >
          > However, this is not happening in my code.
          > I have the following scenario:
          > Container1
          > ->Container2 (child of Container1)
          > -->Datagrid (child of Container2)
          >
          > In container 1, I attempt to register an event listener with the itemClick
          > event of the datagrid using the creationComplete event. This fails.
          > However,
          > if I move this registration to a click event on Container 1, it is
          > successful.
          > So the problem appears to be related to instantiation of the datagrid. So
          > why
          > would the dataGrid not be instantiated by the time the Container1
          > creationComplete event fires?

          Try dispatching a custom bubbling event from the creationComplete event of
          the datagrid that you listen for from Container1. Or, just have Container2
          do the handling and generate a custom event based on the itemClick. That's
          probably the "Flexier" way to handle it.

          HTH;

          Amy


          • 2. Re: Help Understanding Event Model
            Gregory Lafrance Level 6
            If you are dealing with a ViewStack or other navigational container, be aware that child components are not created until that "view" is accessed. You can force all to created with creationPolicy="all" but it can affect performance.

            What are the containers?
            • 3. Re: Help Understanding Event Model
              rss181919 Level 1
              Container1 is a TabNavigator
              Container2 is a panel

              Performance is not an issue for my app so I will try setting the creationPolicy. If that does not work, I will try the bubbling recommendation Amy presented.
              • 4. Re: Help Understanding Event Model
                Level 7

                "rss181919" <webforumsuser@macromedia.com> wrote in message
                news:gfeul0$mhg$1@forums.macromedia.com...
                > Container1 is a TabNavigator
                > Container2 is a panel
                >
                > Performance is not an issue for my app so I will try setting the
                > creationPolicy. If that does not work, I will try the bubbling
                > recommendation
                > Amy presented.

                Please review Q5 first
                http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf


                • 5. Re: Help Understanding Event Model
                  Gregory Lafrance Level 6
                  The problem is probably as I described. Set creationPolicy="all" and all will surely be well.
                  • 6. Re: Help Understanding Event Model
                    rss181919 Level 1
                    Thanks for the FAQ Amy.
                    • 7. Re: Help Understanding Event Model
                      Level 7

                      "rss181919" <webforumsuser@macromedia.com> wrote in message
                      news:gffgvh$ggj$1@forums.macromedia.com...
                      > Thanks for the FAQ Amy.

                      You're welcome :-)