2 Replies Latest reply on Apr 20, 2006 12:53 PM by weanderson

    help with strings

    weanderson Level 1
      I'm trying to push data from a series of combo boxes into an array. I name each box a1, a2, a3, a4, a5 and so on. I have been tring to create a for loop to check which boxes were selected and push the label name to an array. I created a varable ("combo") to dynamically change the name of the combo box I am checking, which displays the correct name, but the .selected and .label return undefined. Not sure what I have done wrong. Any help would be appreciated. Here is the code I am using.

      var AdditionInfo:Array = new Array();


      additional_btn.onPress = function () {
      for (i=1; i<9;i++){
      combo = "a"+i;
      combo.toString();
      trace ("combo: " +combo);
      trace ("combo select: " + combo.selected);
      trace ("combo Label"+i+": "+ combo.label);
      if (combo.selected == true) {
      AdditionInfo.push (combo.label);
      trace ("combo Label:" +combo.label);
      }
      }
      //_root.play ();
      }

      Thanks in advance.
      ..W
        • 1. Re: help with strings
          Level 7
          weanderson,

          > I created a varable ("combo") to dynamically change the
          > name of the combo box I am checking,

          Because of those quotes, there, it looks like "combo" is a String
          variable.

          > which displays the correct name, but the .selected and .label
          > return undefined. Not sure what I have done wrong.

          I'm pretty sure you're trying to reference a ComboBox instance when what
          you're actually referencing is a String instance. And the String class
          doesn't define .selected or .label properties.

          > var AdditionInfo:Array = new Array();

          So far, we have an Array instance.

          > additional_btn.onPress = function () {

          Now, we have a function assigned to the onPress event of a button (or
          maybe a movie clip acting lik a button).

          > for (i=1; i<9;i++){

          for() loop, counting from 1 to 8 ...

          > combo = "a"+i;

          Now we're declaring a variable -- yup, a String instance -- with the
          value a1 (and later, a2, a3, etc.).

          > combo.toString();

          This line doesn't really do anything at all. Object.toString() doesn't
          affect the object at all, but merely returns a String message of some
          kind -- it's String-based "snapshot" of the contents of the object. But
          since you aren't doing anything with the return value, such as
          trace(combo.toString());, the return value doesn't go anywhere. You could
          drop this line altogether.

          > trace ("combo: " +combo);

          Okay, this will show you a1, a2, and so on. But remember, these are
          Strings.

          > trace ("combo select: " + combo.selected);

          This will show you the String.selected property of your particular
          String instance, combo. But there is no String.selected property, so you'll
          see undefined.

          > trace ("combo Label"+i+": "+ combo.label);

          Same here.

          > if (combo.selected == true) {

          This won't work either, for the same reason.

          > AdditionInfo.push (combo.label);
          > trace ("combo Label:" +combo.label);
          > }
          > }
          > //_root.play ();
          > }

          What you need to do is resolve the String into an actual object
          reference. You can do this with the array access operator, [], according to
          the article here ...

          http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: help with strings
            weanderson Level 1
            Thanks for the help. Datatypes are no longer my downfall (at least for now).