3 Replies Latest reply on Apr 18, 2008 9:44 AM by sxp001

    One simple (maybe stupid) question:

      Why I can not rich all my TextInput objects using this code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      import mx.validators.ValidationResult;
      import mx.collections.ArrayCollection;
      import mx.controls.*;
      import mx.events.ItemClickEvent;
      // test for children
      private function ChildrenTest():void
      var bChildren:Array = tnav.getChildren();
      for (var i:uint = 0; i < bChildren.length; i++)
      var cChildren:Array = bChildren .getChildren();
      for (var n:uint = 0; n < cChildren.length; n++)
      if (cChildren[n].constructor == "[class TextInput]")
      Alert.show('on child name ' + cChildren[n].name.toString());
      //Alert.show('on Canvas ' + bChildren
      <mx:Panel id="pnRates" layout="absolute" left="10" top="10" bottom="10" right="10">
      <mx:Button x="29" y="250" label="Test for the loop" click="ChildrenTest();" />
      <mx:TabNavigator id="tnav" width="540" height="170" y="45" x="29">
      <mx:Canvas id="can1" label="Tab 1" width="100%" height="406">
      <mx:Label x="20" y="10" text="TEXT1"/>
      <mx:TextInput x="173" y="8" id="Tab1Value1"/>
      <mx:Label x="20" y="50" text="TEXT2"/>
      <mx:TextInput x="173" y="48" id="Tab1Value2"/>
      <mx:Label x="20" y="90" text="TEXT3"/>
      <mx:TextInput x="173" y="88" id="Tab1Value3"/>
      <mx:Canvas id="can2" label="Tab 2" width="100%" height="100%">
      <mx:Label x="20" y="10" text="TEXT1"/>
      <mx:TextInput x="189" y="8" id="Tab2Value1"/>
      <mx:Label x="20" y="50" text="TEXT2"/>
      <mx:TextInput x="189" y="48" id="Tab2Value2"/>
      <mx:Label x="20" y="90" text="TEXT3"/>
      <mx:TextInput x="189" y="88" id="Tab2Value3"/>
      <mx:Canvas id="can3" label="Tab 3" width="100%" height="100%">
      <mx:Label x="20" y="10" text="TEXT1"/>
      <mx:TextInput x="232" y="8" id="Tab3Value1"/>
      <mx:Label x="20" y="50" text="TEXT2"/>
      <mx:TextInput x="232" y="48" id="Tab3Value2"/>
      <mx:Label x="20" y="90" text="TEXT3"/>
      <mx:TextInput x="232" y="88" id="Tab3Value3"/>

        • 1. Re: One simple (maybe stupid) question:
          Peter deHaan Level 4

          Two things:
          (1) you need to change this line:
          var cChildren:Array = bChildren.getChildren();

          To this:
          var cChildren:Array = bChildren .getChildren();

          Now, when you click the button, it should report the three text inputs on the visible tab. If you click on tab 3, it should report the 3 tabs on tab 3 *and* the 3 tabs on tab 1. Basically, it will only alert the text input children *after* you have clicked on a tab and the tab's contents have been created.

          (2) If you want to create all tabs at once when the app is loaded, change this:
          <mx:TabNavigator id="tnav" width="540" height="170" y="45" x="29">

          to this:
          <mx:TabNavigator id="tnav" width="540" height="170" y="45" x="29" creationPolicy="all">

          Now, when you launch your applicaton, it should display an alert for each TextInput control on each tab, without having to click on each tab.

          Hope that helps,
          • 2. One simple (maybe stupid) question:
            VarioPegged Level 2
            Peter, may I add something that should be noted here on these forums... and it would be great if you could somehow write up something short on this and create it as a sticky post.

            Whenever code is entered inline (not using "Attach Code") and a variable is assigned in a for loop, please do not use the character "i" for that variable. This forum always reads that as an "italic" tag, messing up the remainder of the code and stripping out that tag.

            The answer you provided is a good example of this problem. With the way it renders on this forum there's no difference between what his original code is and what you're citing as part of the answer:
            var cChildren:Array = bChildren.getChildren();

            Use ANY character other than "i":

            var cChildren:Array = bChildren[a].getChildren();
            var cChildren:Array = bChildren[j].getChildren();
            or anything else for that matter...


            • 3. Re: One simple (maybe stupid) question:
              sxp001 Level 1
              Hi Peter,
              THANKS A LOT!
              Now works perfect.
              TS, this is an excellent point, many times I was confused with code from the Forum.