16 Replies Latest reply on Feb 2, 2009 2:41 PM by Newsgroup_User

    Navigation to SubChild Problem

    amnesiaiom
      Hey,

      I'm trying to navigate to a subchild of the main ViewStack within my application to create a site map for my application.

      For example:

      <mx:ViewStack id="myViewStack">
      <mx:HBox id="one">
      <mx:ViewStack id="secondViewStack">
      <mx:HBox id="two">
      </mx:HBox>
      <mx:HBox id="three">
      </mx:HBox>
      </mx:ViewStack>
      </mx:HBox>
      </mx:ViewStack>

      I can get to HBox "one" by using myViewStack.selectedindex=0; or myViewStack.selectedChild=one; but how do I get to HBox two or three?

      I've searched the internet extensively, and can't find anything at all about this.. Any ideas?

      Your help is much appreciated! :o)
        • 1. Re: Navigation to SubChild Problem
          Cesare Rocchi Level 2
          If I read correctly your code to access "two" you need a

          myViewStack.secondViewStack.selectedindex = 0;

          and to access "three"

          myViewStack.secondViewStack.selectedindex = 1;

          Is that what you mean?
          • 2. Re: Navigation to SubChild Problem
            amnesiaiom Level 1
            Hey thanks for the reply.

            myViewStack.secondViewStack.selectedIndex=1; doesn't work, I get a 1119:Access to undefined property error.

            Is this because the second ViewStack is held within the HBox?
            • 3. Re: Navigation to SubChild Problem
              Cesare Rocchi Level 2
              Right. I misread your code (not easy without indentation :)

              myViewStack.one.secondViewStack.two

              is the correct one.

              Think of the dot as a sort of "getChildWithName" method.

              -c.
              • 4. Re: Navigation to SubChild Problem
                Level 7

                "amnesiaiom" <webforumsuser@macromedia.com> wrote in message
                news:gm6orr$3il$1@forums.macromedia.com...
                > Hey thanks for the reply.
                >
                > myViewStack.secondViewStack.selectedIndex=1; doesn't work, I get a
                > 1119:Access to undefined property error.
                >
                > Is this because the second ViewStack is held within the HBox?

                http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
                Q5


                • 5. Re: Navigation to SubChild Problem
                  levancho Level 3
                  quote:

                  Originally posted by: _funkyboy
                  Right. I misread your code (not easy without indentation :)

                  myViewStack.one.secondViewStack.two

                  is the correct one.

                  Think of the dot as a sort of "getChildWithName" method.

                  -c.


                  thati is incorrect,

                  ID is a shorthand of flex creating instance variable, something like var one:HBox etc ...

                  in your example, every component that has ID assigned to it, is directly accessible from the component that fragment is declared in, so if that component is main application, then you can just say "this.one" and you will get reference of hBox which is child of your second ViewStack and has id="one", so,--> myViewStack.one.secondViewStack.two is not correct,
                  on the other hand, if you want to create a sitemap than IMHO using ids is lincorrect way to achieve that, imagine if you need to add more hboxes to viewtack, you will have to change your sitemap code too.
                  instead look here : http://livedocs.adobe.com/flex/3/langref/ for viewStack and use its api methods, for example
                  getChildren(0 returns array of childre it has, this way sitemap will be more dynamic.


                  • 6. Re: Navigation to SubChild Problem
                    Cesare Rocchi Level 2
                    You are right. I didn't think of that. Sorry.
                    • 7. Re: Navigation to SubChild Problem
                      levancho Level 3
                      quote:

                      Originally posted by: _funkyboy
                      You are right. I didn't think of that. Sorry.

                      np :) its Monday after all :) it happens to me a lot too
                      • 8. Re: Navigation to SubChild Problem
                        Level 7

                        "levancho" <webforumsuser@macromedia.com> wrote in message
                        news:gm77o9$lqc$1@forums.macromedia.com...
                        >
                        quote:

                        Originally posted by: _funkyboy
                        > Right. I misread your code (not easy without indentation :)
                        >
                        > myViewStack.one.secondViewStack.two
                        >
                        > is the correct one.
                        >
                        > Think of the dot as a sort of "getChildWithName" method.
                        >
                        > -c.

                        >
                        > thati is incorrect,
                        >
                        > ID is a shorthand of flex creating instance variable, something like var
                        > one:HBox etc ...
                        >
                        > in your example, every component that has ID assigned to it, is directly
                        > accessible from the component that fragment is declared in, so if that
                        > component is main application, then you can just say "this.one" and you
                        > will
                        > get reference of hBox which is child of your second ViewStack and has
                        > id="one",
                        > so,--> myViewStack.one.secondViewStack.two is not correct,
                        > on the other hand, if you want to create a sitemap than IMHO using ids is
                        > lincorrect way to achieve that, imagine if you need to add more hboxes to
                        > viewtack, you will have to change your sitemap code too.
                        > instead look here : http://livedocs.adobe.com/flex/3/langref/ for
                        > viewStack
                        > and use its api methods, for example
                        > getChildren(0 returns array of childre it has, this way sitemap will be
                        > more
                        > dynamic.

                        All of the id's are in the Application domain. The only reason he's getting
                        an access of undefined property error is because the object he's trying to
                        get hold of hasn't been created yet.


                        • 9. Re: Navigation to SubChild Problem
                          Level 7

                          "_funkyboy" <webforumsuser@macromedia.com> wrote in message
                          news:gm78ev$mna$1@forums.macromedia.com...
                          > You are right. I didn't think of that. Sorry.

                          He's not, which is probably why you didn't LOL.


                          • 10. Re: Navigation to SubChild Problem
                            levancho Level 3
                            quote:

                            Originally posted by: Newsgroup User

                            "levancho" <webforumsuser@macromedia.com> wrote in message
                            news:gm77o9$lqc$1@forums.macromedia.com...
                            >
                            quote:

                            Originally posted by: _funkyboy
                            > Right. I misread your code (not easy without indentation :)
                            >
                            > myViewStack.one.secondViewStack.two
                            >
                            > is the correct one.
                            >
                            > Think of the dot as a sort of "getChildWithName" method.
                            >
                            > -c.

                            >
                            > thati is incorrect,
                            >
                            > ID is a shorthand of flex creating instance variable, something like var
                            > one:HBox etc ...
                            >
                            > in your example, every component that has ID assigned to it, is directly
                            > accessible from the component that fragment is declared in, so if that
                            > component is main application, then you can just say "this.one" and you
                            > will
                            > get reference of hBox which is child of your second ViewStack and has
                            > id="one",
                            > so,--> myViewStack.one.secondViewStack.two is not correct,
                            > on the other hand, if you want to create a sitemap than IMHO using ids is
                            > lincorrect way to achieve that, imagine if you need to add more hboxes to
                            > viewtack, you will have to change your sitemap code too.
                            > instead look here : http://livedocs.adobe.com/flex/3/langref/ for
                            > viewStack
                            > and use its api methods, for example
                            > getChildren(0 returns array of childre it has, this way sitemap will be
                            > more
                            > dynamic.

                            All of the id's are in the Application domain. The only reason he's getting
                            an access of undefined property error is because the object he's trying to
                            get hold of hasn't been created yet.





                            I dont know where are you getting this from ;

                            from Lang Ref : ID of the component. This value becomes the instance name of the object and should not contain any white space or special characters. Each component throughout an application should have a unique id.

                            ID scope is defined based on where they are defined in, if you define id "abc" of a Box, inside your custom component you can not reference abc inside application like "this.abc" will not work.

                            and reason he is getting the error is not because hbox is not created yet, but because

                            ref : myViewStack.secondViewStack.selectedIndex
                            secondViewStack is not created yet so accessing propert yof null object.
                            you can always get refference of the object by its id, its not goign to throw error, maye refference will not point to obj yet but you still gonna have a correct memory address.
                            hope thats clear
                            regards
                            levan.


                            • 11. Re: Navigation to SubChild Problem
                              amnesiaiom Level 1
                              Hey

                              quote:

                              instead look here : http://livedocs.adobe.com/flex/3/langref/ for viewStack and use its api methods, for example getChildren(0 returns array of childre it has, this way sitemap will be more dynamic.


                              There is no method within the ViewStack API called getChildren, there are only: loadState and saveState within the methods area.


                              quote:

                              and reason he is getting the error is not because hbox is not created yet, but because ref : myViewStack.secondViewStack.selectedIndex secondViewStack is not created yet so accessing propert yof null object. you can always get refference of the object by its id, its not goign to throw error, maye refference will not point to obj yet but you still gonna have a correct memory address. hope thats clear


                              So if they aren't created I can't ever access them?

                              So are you saying that it will tell me there's an error, but I should run it anyway? I do not get an error if I am trying to access a child of a ViewStack, only when I am trying to go deeper... when I use myViewStack.selectedChild= one; this is absolutely fine, but when I try to get two or three FlexBuilder complains.

                              I'm sorry but this has confused me!

                              I have tried:

                              myViewStack.one.secondViewStack.three
                              myViewStack.secondViewStack.three
                              this.three

                              None of the above work, please could someone just let me know how I can access the subChildren? Thanks!
                              • 12. Re: Navigation to SubChild Problem
                                levancho Level 3
                                quote:


                                There is no method within the ViewStack API called getChildren, there are only: loadState and saveState within the methods area.

                                there is, its just hidden, click on "show inherited methods" and it will show up.


                                that happens because components are not ll created they get created lazily when they are needed, for example when you request to have hbox 2 to be shown in your wievstack flex creates hbox then, and it reuses it afterwords, you can controlc reation process with property creationPolicy
                                see : this link : http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_05.html
                                • 13. Re: Navigation to SubChild Problem
                                  Cesare Rocchi Level 2
                                  If you want to be sure it exists you have to set the creationPolicy to all
                                  like this:

                                  <ViewStack creationPolicy="all">...</ViewStack>

                                  This ensures that all the "children" of the viewstack are created at the beginning. So whenever you call "this.one" you are sure it exists.

                                  By default creationPolicy is set to "auto" which creates just the first element of the stack and the rest gets created as you select the items. And this is why secondViewStack.three does not work in your example.

                                  The con of setting creationPolicy to "all" is that it takes more time (and more memory) at startup to draw the graphics of your application.

                                  More on creationPolicy here: http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_05.html
                                  • 14. Navigation to SubChild Problem
                                    amnesiaiom Level 1
                                    So it is to do with the containers not created? I'll try that now.
                                    • 15. Re: Navigation to SubChild Problem
                                      amnesiaiom Level 1
                                      Thanks everyone, I have now solved it... I have added creationPolicy="all" to my viewStacks and created a function which will navigate the nested viewStack to the correct child, and then move to the upper viewStack:
                                      • 16. Re: Navigation to SubChild Problem
                                        Level 7

                                        "levancho" <webforumsuser@macromedia.com> wrote in message
                                        news:gm7bbm$qe9$1@forums.macromedia.com...
                                        >
                                        quote:

                                        Originally posted by: Newsgroup User
                                        >
                                        > "levancho" <webforumsuser@macromedia.com> wrote in message
                                        > news:gm77o9$lqc$1@forums.macromedia.com...
                                        > >
                                        quote:

                                        Originally posted by: _funkyboy
                                        > > Right. I misread your code (not easy without indentation :)
                                        > >
                                        > > myViewStack.one.secondViewStack.two
                                        > >
                                        > > is the correct one.
                                        > >
                                        > > Think of the dot as a sort of "getChildWithName" method.
                                        > >
                                        > > -c.

                                        > >
                                        > > thati is incorrect,
                                        > >
                                        > > ID is a shorthand of flex creating instance variable, something like var
                                        > > one:HBox etc ...
                                        > >
                                        > > in your example, every component that has ID assigned to it, is directly
                                        > > accessible from the component that fragment is declared in, so if that
                                        > > component is main application, then you can just say "this.one" and you
                                        > > will
                                        > > get reference of hBox which is child of your second ViewStack and has
                                        > > id="one",
                                        > > so,--> myViewStack.one.secondViewStack.two is not correct,
                                        > > on the other hand, if you want to create a sitemap than IMHO using ids
                                        > > is
                                        > > lincorrect way to achieve that, imagine if you need to add more hboxes
                                        > > to
                                        > > viewtack, you will have to change your sitemap code too.
                                        > > instead look here : http://livedocs.adobe.com/flex/3/langref/ for
                                        > > viewStack
                                        > > and use its api methods, for example
                                        > > getChildren(0 returns array of childre it has, this way sitemap will be
                                        > > more
                                        > > dynamic.
                                        >
                                        > All of the id's are in the Application domain. The only reason he's
                                        > getting
                                        > an access of undefined property error is because the object he's trying to
                                        > get hold of hasn't been created yet.
                                        >
                                        >
                                        >

                                        >
                                        > I dont know where are you getting this from ;
                                        >
                                        > from Lang Ref : ID of the component. This value becomes the instance
                                        > name
                                        > of the object and should not contain any white space or special
                                        > characters.
                                        > Each component throughout an application should have a unique id.

                                        >
                                        > ID scope is defined based on where they are defined in, if you define id
                                        > "abc"
                                        > of a Box, inside your custom component you can not reference abc inside
                                        > application like "this.abc" will not work.
                                        >
                                        > and reason he is getting the error is not because hbox is not created yet,
                                        > but
                                        > because
                                        >
                                        > ref : myViewStack.secondViewStack.selectedIndex
                                        > secondViewStack is not created yet so accessing propert yof null
                                        > object.
                                        > you can always get refference of the object by its id, its not goign to
                                        > throw
                                        > error, maye refference will not point to obj yet but you still gonna have
                                        > a
                                        > correct memory address.
                                        > hope thats clear

                                        It is, but you are misinterpreting it. The only way something inside an
                                        Application tag _at any level_ would be outside of its document scope is
                                        because it is in a <component> tag or is in a different MXML file.

                                        Try this:

                                        New Application w 100% h100%
                                        Put a VBox id "foo" inside the Application w 100% h100%
                                        Put a Canvas id "bar" inside foo w 100% h100%
                                        put a Button id "theButton" inside bar

                                        now go to the Applcation tag and add
                                        creationComplete="theButton.label='see?'"

                                        What happens?