3 Replies Latest reply on May 7, 2008 12:39 PM by VarioPegged

    Accessing components in TabNavigator on unselected tabs

    ScoobaSteve1982
      Hi there,

      I want to set the value of components (says a rich text editor, or image source attribute value, etc.) in tabs that are NOT selected. So if I have three tabs say, and I currently have tab 1 selected and I want to set the value of a text field that is visible when tab 2 is selected...how can I achieve this? I know the TabNavigator extends the ViewStack class but I'm new to Flex and am having difficulty with this. In Java it's a very easy process so I'm assuming it would be quite similar in Flex...any help is greatly appreciated. Thanks!
        • 1. Re: Accessing components in TabNavigator on unselected tabs
          Gregory Lafrance Level 6
          I would think this code works, but it gives an error. Anyone know why?

          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Script>
          <![CDATA[
          import mx.containers.VBox;
          private function clickHandler():void{
          tb.getChildByName("futures").futuresLbl.text = "New Futures Information";
          }
          ]]>
          </mx:Script>
          <mx:TabNavigator id="tb" borderStyle="solid" creationPolicy="all">
          <mx:VBox name="accounts" label="Accounts"
          width="300"
          height="150">
          <mx:Label text="Accounts Information"/>
          </mx:VBox>
          <mx:VBox name="stocks" label="Stocks"
          width="300"
          height="150">
          <mx:Label text="Stocks Information"/>
          </mx:VBox>
          <mx:VBox name="futures" label="Futures"
          width="300"
          height="150">
          <mx:Label id="futuresLbl" text="Futures Information"/>
          </mx:VBox>
          </mx:TabNavigator>
          <mx:Button label="Change Futures Text" click="clickHandler()"/>
          </mx:Application>
          • 2. Re: Accessing components in TabNavigator on unselected tabs
            ScoobaSteve1982 Level 1
            I tried that too and it didn't work for me either. This seems like something that would be relatively easy...
            • 3. Re: Accessing components in TabNavigator on unselected tabs
              VarioPegged Level 2
              quote:

              I would think this code works, but it gives an error. Anyone know why?


              You can't use dot syntax to refer to components that way. If you know what that component's id ("futuresLbl") is, why would you use such a roundabout way to refer to it anyway? From the Flex docs:

              The IDs for all tags in an MXML component, no matter how deeply nested they are, generate public variables of the component being defined. As a result, all id properties must be unique within a document. This also means that if you specified an ID for a component instance, you can access that component from anywhere in the application: from functions, external class files, imported ActionScript files, or inline scripts.

              I imagine if you want to do it the roundabout way, you'd have to cast the individual DisplayObjects to the proper type and then set the text property on the Label. Note that I use a name attribute "futuresLbl" for the Label

              private function clickHandler():void{
              var myVBox:VBox = tb.getChildByName("futures") as VBox;
              var myLabel:Label = myVBox.getChildByName("futuresLbl") as Label;
              myLabel.text = "New Futures Information";
              }

              TS