4 Replies Latest reply on Aug 21, 2008 9:50 AM by Newsgroup_User

    Problem accessing an object in a VBox

    Jimmy_Jeeves
      Hi!

      I have a problem accessing an object which is in a VBox.
      I made an example so you can see my problem. I am trying to access pnlChat.
      If you load the swf you won't see the Alert because there is something wrong (and I don't know what)
      If you try to remove the <mx:VBox> tags that wrap the pnlChat Panel, it will work.

      Why can't I access this object when it is in a VBox?

      Thanks
        • 1. Re: Problem accessing an object in a VBox
          Level 7

          "Jimmy Jeeves" <webforumsuser@macromedia.com> wrote in message
          news:g8jv84$5ib$1@forums.macromedia.com...
          > Hi!
          >
          > I have a problem accessing an object which is in a VBox.
          > I made an example so you can see my problem. I am trying to access
          > pnlChat.
          > If you load the swf you won't see the Alert because there is something
          > wrong
          > (and I don't know what)
          > If you try to remove the <mx:VBox> tags that wrap the pnlChat Panel, it
          > will
          > work.
          >
          > Why can't I access this object when it is in a VBox?

          From the FAQ I'm compiling:

          Q: I need to set a property or add an event listener on a component
          that is in a ViewStack/TabNavigator/Accordion. When the component is not
          the first child of the Navigator Container, I get a null object error
          (#1009). What causes this, and how can I fix it?
          A: By default, the Navigator containers only create the children of
          each pane as that pane is viewed. The easy way to fix this is to set the
          creationPolicy on the Navigator to "all." However, this will cause your
          application to take longer to load. A better way to fix this is to wait for
          a later event, such as creationComplete on the component you want to access,
          or to use binding to "pull" the data into the component.
          The way I handle it is to call invalidateProperties() on change of the
          ViewStack. I then override commitProperties() and call an "initializer" for
          each pane. In the body of each initializer function, I check to see if the
          selectedItem for the viewStack is the one my initalizer cares about. If
          not, I return from the function immediately. Inside that initializer
          function, I set properties and add listeners as appropriate.


          • 2. Re: Problem accessing an object in a VBox
            Jimmy_Jeeves Level 1
            Thank you Amy.

            I tried with creationPolicy and it works.

            The thing is, in my application (the code here is just en example), I am showing the panel before trying to accessing it.

            vsMain.selectedChild = pnlVideo; // pnlVideo is the VBox
            Alert.show(pnlChat.title);

            I guess pnlChat is not completely loaded even I asked it to be displayed.

            I do some tests and come back if it does work.
            Thank you.
            • 3. Re: Problem accessing an object in a VBox
              Jimmy_Jeeves Level 1
              Ok I tried something and it works, can you please tell me if it's a good way to do it?
              Actually I am trying to change the title, not to get it.

              I created a variable:

              [Bindable]
              public var chatTitle:String = "Chat";

              And my panel:

              <mx:Panel
              id="pnlChat"
              title="{chatTitle}"
              width="100%" height="230">

              And when I want to load the panel:

              chatTitle = "Chat: " + roomname; // Some variable
              vsMain.selectedChild = pnlVideo; // Change to the chat view
              • 4. Re: Problem accessing an object in a VBox
                Level 7

                "Jimmy Jeeves" <webforumsuser@macromedia.com> wrote in message
                news:g8k0p0$7pi$1@forums.macromedia.com...
                > Thank you Amy.
                >
                > I tried with creationPolicy and it works.
                >
                > The thing is, in my application (the code here is just en example), I am
                > showing the panel before trying to accessing it.
                >
                > vsMain.selectedChild = pnlVideo; // pnlVideo is the VBox
                > Alert.show(pnlChat.title);
                >
                > I guess pnlChat is not completely loaded even I asked it to be displayed.

                No, not at that point. Try putting that in the creationComplete event of
                pnlChat.

                HTH;

                Amy