8 Replies Latest reply on Nov 5, 2008 3:02 PM by Mitek17

    viewstack - addchild issue

    ethr
      Im using a 'template' of sorts to populate a viewstack at run time. The panes are available (if I link the viewstack to a linkbar I can navigate) and appear functional.

      The problem occurs if I attempt to access a specific pane via the viewstack object (via its 'id'). If I have 2 panels in it at design time and add two more at run time I will only see the 2 original panels if I look at the 'childDescriptors' array.

      What I'm hoping to achieve is to be able to set the active panel at runtime using the selection from the linkbar - without binding to the viewstack (using the 'selectedChild' value).

      Summary:
      a) why aren't the runtime 'children' appearing in the childdescriptors array?
      b) is there some other way to add children at runtime such that they are accessible via AS?
        • 1. Re: viewstack - addchild issue
          dmindler

          try:

          viewStack.addChild(child1);
          viewStack.addChild(child2);
          viewStack.invalidateDisplayList();

          • 2. Re: viewstack - addchild issue
            ethr Level 1
            Unfortunately it didn't work.

            From the docs I get the impression that invalidateDisplayList is more of a UI thing than an internals thing. IE it marks a UI object as 'dirty' for redrawing later.
            • 3. Re: viewstack - addchild issue
              dmindler Level 1

              I'm reading the code to ViewStack/Container and I'm not sure you want the child descriptors.

              Don't you want the Container.getChildAt() method instead? you can also use getChildByName() if you assign a name to the stack component.


              http://livedocs.adobe.com/flex/201/langref/mx/core/Container.html#getChildAt()
              • 4. viewstack - addchild issue
                ethr Level 1
                I'd been using getChildByName in the past. It works fine with the design time components but not the run time. getChildAt won't work as the array of children in the viewStack doesn't include the panels added at run time. I would get an 'out of bounds' error.

                I was using childDescriptors as a way of seeing what was in the viewstack array.

                Interestingly enough the $numChildren attribute of the viewstack has the correct value.
                • 5. Re: viewstack - addchild issue
                  Level 7

                  "ethr" <webforumsuser@macromedia.com> wrote in message
                  news:genkbq$4bq$1@forums.macromedia.com...
                  > I'd been using getChildByName in the past. It works fine with the design
                  > time
                  > components but not the run time. getChildAt won't work as the array of
                  > children
                  > in the viewStack doesn't include the panels added at run time. I would get
                  > an
                  > 'out of bounds' error.

                  I think getChildByName really works off of the id, despite the name of the
                  function. The id of a child created at design time is an integral part of
                  the object, whereas with one created at runtime it's just sort of "stuck
                  on", and isn't able to perform all functions of the id created in MXML.

                  HTH;

                  Amy


                  • 6. Re: viewstack - addchild issue
                    Mitek17 Level 1
                    Did you try to set viewstack.createChildrenPolicy="all" ?

                    By default, viewstack, accordion and the rest, do not create all children components, only the first visible one to save the initialisation time.


                    Cheers,
                    Dmitri.
                    • 7. Re: viewstack - addchild issue
                      ethr Level 1
                      Tried it. No go.

                      I found a few bugs w/re to ViewStack and createChild in JIRA. Looks like it wasn't properly tested before it was shipped.

                      Here's what Im trying to achieve:
                      Box with a vertical divider. On the left side is a linkbar and a viewstack with n children on the right. One of the stack components has a datagrid with checkboxes for each linkbar entry. It lets you decide whether or not to display a given linkbar (and thus, a page) when the frame is loaded. I had the code working fine when I was loading all the viewstack components at design time.

                      So I try to get fancy and make a template. I load some components at design time and others at run time. Now the only components that I can reference (at run time) are those that are preloaded (IE at design).

                      Its my understanding (albeit limited) that the MXML compiler turns all that XML into actionscript. The trick seems to be discovering how it interprets the design time items vs those that Im trying to add later.
                      • 8. Re: viewstack - addchild issue
                        Mitek17 Level 1
                        As far as I understand, you are trying to use the dynamic object within the viewstack component.
                        If this so, you should use events to synchronise object creation and control. I.e. if you create any object in AS, then add this object as a child, you won't be able to access it's properties straight away, you have to wait for creationComplete event at least. If you adding a child to the container, you have to wait for the event "added" (or whatever it is called).
                        If your thing works when all objects are created from MXML and don't work when you dynamically create them from AS, the first thing you should check - how do you synchronise objects.
                        Hope this helps.

                        Cheers,
                        Dmitri.