6 Replies Latest reply on Jun 21, 2011 11:25 AM by Ned Murphy

    mgB[i].ivar=i

    Ron Colmen Level 2

      This is the code for the array of comboboxes. mgBW[this.ivar]=currentlySelectedX.label is not functioning...

       

      var mgB:Array = [ab1, ab2, ab3]; // combo boxes

      var mgBW:Array = [_root.xy1.text, _root.xy2.text, _root.xy3.text]; // text fields

       

       

      for (i=0; i<mgB.length; i++) {

      mgB[i].addItem("Please Select");

      mgB[i].addItem({data:1, label:"Item"});

      mgB[i].addItem({data:2, label:"Quantity"});

       

      }

       

       

      for (i=0; i<mgB.length; i++) {

      mgB[i].ivar=i;

      mgB[i].addEventListener("change", cbListenerX);

       

      var cbListenerX:Object = new Object();

      cbListenerX.change = function(evt_objX:Object):Void{

      var currentlySelectedX:Object = evt_objX.target.selectedItem;

      mgBW[this.ivar]=currentlySelectedX.label;

      //trace (mgBW[this.ivar]);

      }

      };

        • 1. Re: mgB[i].ivar=i
          Ned Murphy Adobe Community Professional & MVP

          Try the following instead.  If you want to have separate loops, you can, but for what you show it is not necessary, and if you do have separate loops it is best to use a different counter variable name ( i j k l  etc ) for each loop in the same scope.

           

          The way you have the textfield array written out is probably not what you intend... it is only storing the textfield text values, which are probably empty strings.   The textfield array is changed to hold the textfields, not the text value that the textfields hold.

           

          In the change function I removed the usage of "this" and make use of the event target that gets handed to the function.  Also, the assignment of the listener is moved until after the listener is defined.

           

           

          var mgB:Array = [ab1, ab2, ab3]; // combo boxes
          var mgBW:Array = [_root.xy1, _root.xy2, _root.xy3]; // text fields

           

          for (i=0; i<mgB.length; i++) {

             mgB[i].addItem("Please Select");
             mgB[i].addItem({data:1, label:"Item"});
             mgB[i].addItem({data:2, label:"Quantity"});

           

             mgB[i].ivar=i;

           

             var cbListenerX:Object = new Object();
             cbListenerX.change = function(evt_objX:Object):Void{
                 var currentlySelectedX:Object = evt_objX.target.selectedItem;
                 mgBW[evt_objX.target.ivar].text=String(currentlySelectedX.label);
             }
             mgB[i].addEventListener("change", cbListenerX);
          };

          • 2. Re: mgB[i].ivar=i
            Ron Colmen Level 2

            Thanks Ned!!!

            • 3. Re: mgB[i].ivar=i
              Ron Colmen Level 2

              I have a similar situation with the onChange() function. Any idea why isn't this working?

               

              var mgB:Array = [ab1, ab2, ab3];// 1 set of text fields

              var mgXB:Array = [_root.xy1.ab1, _root.xy2.ab2, _root.xy3.ab3]; // 2nd set of text fields

               

              for (j=0; j<12; j++) {

              mgB[j].ivr = j

              mgB[j].onChanged = function () {

              trace (mgXB[this.ivr]) // undefined!

              mgXB[this.ivr].text=mgB[j].text

              }

              }

              • 4. Re: mgB[i].ivar=i
                Ned Murphy Adobe Community Professional & MVP

                If you are getting an undefined for that line, then there is something wrong with the setup/naming of the objects.  If there are textfields with those "ab#" names inside movieclips with those "xy#" names, then the trace should display the object's target path

                 

                As for the last line of that function, that will be wrong for reasons you should already be familiar with since the last couple of times I helped you it was the same problem.

                1 person found this helpful
                • 5. Re: mgB[i].ivar=i
                  Ron Colmen Level 2

                  Got it working!! Thanks Ned!!!!

                  • 6. Re: mgB[i].ivar=i
                    Ned Murphy Adobe Community Professional & MVP

                    You're Welcome Ron