8 Replies Latest reply on Oct 23, 2008 10:33 AM by dnbwise

    viewstack question

    dnbwise
      i've global variables viewStack and vsArray initialized. vsArray is a map of a string keys to ViewStacks. viewStack is set to a ViewStack via of a key e.g.

      function setViewStack(key:String) {
      viewStack.removeAllChildren(); //reset viewStack
      for each(var do:DisplayObject in vsArray[key].getChildren()) { viewStack.addChild(do); }
      }

      the problem that seems to be arising is that once this loop runs for a given key, then the ViewStack indexed by that key no longer has children. i can't figure out why that is...can someone please enlighten me here?
        • 1. Re: viewstack question
          Gregory Lafrance Level 6
          ViewStack children are not initialized until they are first accessed. You can get around this by setting creationPolicy=all, though this could affect performance depending on what gets created.
          • 2. Re: viewstack question
            Level 7

            "dnbwise" <webforumsuser@macromedia.com> wrote in message
            news:gb72of$jfl$1@forums.macromedia.com...
            > i've global variables viewStack and vsArray initialized.
            > vsArray is a map of a string keys to ViewStacks. viewStack
            > is set
            > to a ViewStack via of a key e.g.
            >
            > function setViewStack(key:String) {
            > viewStack.removeAllChildren(); //reset viewStack
            > for each(var do:DisplayObject in vsArray[key].getChildren()) {
            > viewStack.addChild(do); }
            > }
            >
            > the problem that seems to be arising is that once this loop runs for a
            > given
            > key, then the ViewStack indexed by that key no longer has children. i
            > can't
            > figure out why that is...can someone please enlighten me here?

            When you add the children from one container to a different container, the
            children are no longer in the first container. They are where you put
            them--in the new container.

            HTH;

            Amy


            • 3. Re: viewstack question
              dnbwise Level 1
              thank you amy, makes perfect sense. do i need to clone the object to accomplish this task?
              • 4. Re: viewstack question
                Level 7

                "dnbwise" <webforumsuser@macromedia.com> wrote in message
                news:gb96n8$act$1@forums.macromedia.com...
                > thank you amy, makes perfect sense. do i need to clone the object to
                > accomplish this task?

                I'm not sure I've ever run across anything that has a clone method in Flex
                other than the Event classes. You could probably extend a class to add a
                clone method, I suppose. But I think you're going to have to just create a
                new object with the same properties.

                HTH;

                Amy


                • 5. Re: viewstack question
                  g-s-b Level 1
                  I saw somewhere a simple "serialization / deserialization" to create the clone, though I have never tried it myself.

                  • 6. Re: viewstack question
                    Level 7

                    "g-s-b" <webforumsuser@macromedia.com> wrote in message
                    news:gb9pf6$1hn$1@forums.macromedia.com...
                    >I saw somewhere a simple "serialization / deserialization" to create the
                    >clone, though I have never tried it myself.

                    I think that's to do with RemoteObjects.


                    • 7. Re: viewstack question
                      dnbwise Level 1
                      quote:

                      Originally posted by: Newsgroup User

                      "dnbwise" <webforumsuser@macromedia.com> wrote in message
                      news:gb96n8$act$1@forums.macromedia.com...
                      > thank you amy, makes perfect sense. do i need to clone the object to
                      > accomplish this task?

                      I'm not sure I've ever run across anything that has a clone method in Flex
                      other than the Event classes. You could probably extend a class to add a
                      clone method, I suppose. But I think you're going to have to just create a
                      new object with the same properties.

                      HTH;

                      Amy





                      How would I create a new object with the same properties without a cloning method? I need to make a copy of either the array retured by vsArray[key].getChildren() or a copy of each child in that array. for instace,

                      function setViewStack(key:String) {
                      viewStack.removeAllChildren(); //reset viewStack
                      for each(var do:DisplayObject in vsArray[key].getChildren()) {
                      tmp:DisplayObject = clone(do); //clone makes a copy of do
                      viewStack.addChild(tmp);
                      }
                      }
                      • 8. viewstack question
                        dnbwise Level 1
                        I've remedied this issue by moving the children from the vsArray to the viewStack and vise versa as needed.