9 Replies Latest reply on Aug 13, 2008 11:43 AM by vikceo

    iterating array

    vikceo
      i have an array created at run time.. now i want to iterate it for getting values... to display values on some mxml components....

      i cannot use getItemAt .. is there anything like next() (in java list collection) to do the same here?
        • 1. Re: iterating array
          g-s-b Level 1
          var array:Array = [ 1, 2, 3, 4 ];
          for( var i:unit = 0 ; i < array.length ; i++ ) trace( array[ i ] );

          something like that should do.

          • 2. Re: iterating array
            Gregory Lafrance Level 6
            Or this:

            var array:Array = [ 1, 2, 3, 4 ];
            for each ( var i:unit in array){
            trace( array[ i ] );
            }
            • 3. Re: iterating array
              Level 7

              "vikceo" <webforumsuser@macromedia.com> wrote in message
              news:g70jn9$eor$1@forums.macromedia.com...
              >i have an array created at run time.. now i want to iterate it for getting
              > values... to display values on some mxml components....
              >
              > i cannot use getItemAt .. is there anything like next() (in java list
              > collection) to do the same here?

              Why not just use a repeater?


              • 4. Re: iterating array
                Gregory Lafrance Level 6
                A Repeater might be used depending on the situation, but the original requirement was to loop through an array, and for that I'm not sure Repeater would appropriate.
                • 5. Re: iterating array
                  vikceo Level 1
                  right.,.. i cannot user repeater.. also foreach will not work as i m not doing i am not doing it in action script...
                  • 6. Re: iterating array
                    Level 7

                    "Greg Lafrance" <glafrance@chikaradev.com> wrote in message
                    news:g7218u$1n6$1@forums.macromedia.com...
                    >A Repeater might be used depending on the situation, but the original
                    >requirement was to loop through an array, and for that I'm not sure
                    >Repeater would appropriate.

                    It was to iterate through an array _in order to set values on some MXML
                    components_


                    • 7. Re: iterating array
                      g-s-b Level 1
                      vikceo,

                      You should post some code for it is silly to continue guessing as to what you want/need.

                      • 8. Re: iterating array
                        Gregory Lafrance Level 6
                        If you are not doing this in AS, then I guess you are trying to do this in MXML. But in that case your thought process to get this done will be far more complex, as you are trying to fix a square peg in a round hole, while the round peg is right next to you. Do it in AS, that's where the power is anyway.
                        • 9. Re: iterating array
                          vikceo Level 1
                          ok so here is the exact requirement:

                          I have a custom component ... unfortunately it is not supporting repeater component inside it.

                          So, i created the stuff in my mxml like:

                          <components:myComp>
                          <mx:Canvas label="A" />
                          <mx:Canvas label="B" />
                          <mx:Canvas label="C" />
                          </components:myComp>

                          Now if you notice above the three canvases having label A, B and C.

                          I have an array collection which is declared like:
                          <mx:ArrayCollection id="vik" source="{getLabels()}"/>

                          this getLabels() actually returns me an array of 3 items.

                          Now, I want to use some expression for label for the three canvases so assin them the values from array.

                          Right now I am using it like
                          <mx:Canvas label="{vik.getItemAt(0)}" />

                          so the question is: is there a better way to do this? i dont want to use array indexes... can i create some iterator sort of stuff (as we do in java) and use a statement like:
                          label = "{vik.next()}