7 Replies Latest reply on Jan 17, 2007 12:26 AM by weiwuliang

    ID value in the loop

    weiwuliang Level 1
      Hi, I am using Repeater to display the results like:
      the VIDEO_ARRAY is
      public var VIDEO_ARRAY:Array = [{label:"Video", source:"video.flv"}]

      <mx:Repeater id="videoRP" dataProvider="{VIDEO_ARRAY}">
      <mx:VBox horizontalAlign="center" verticalAlign="middle" verticalGap="0" borderStyle="none" width="180" height="180">
      <mx:VideoDisplay id="myVid" height="100" width="100" source="{videoRP.currentItem.source}" autoPlay="false"/>

      <mx:HBox>
      <mx:Button label="Play" click="myVid.play();"/>
      <mx:Button label="Pause" click="myVid.pause();"/>
      <mx:Button label="Stop" click="myVid.stop();"/>
      </mx:HBox>
      </mx:VBox>
      </mx:Repeater>

      if the VIDEO_ARRAY only have 1 value then there is no problem, but when the VIDEO_ARRAY have more values then it will have problem. So anyone know how to set the ID value?

      I am tryied in this way
      id="myVid{videoRP.currentIndex.toString()}"
      and the button is:
      <mx:Button label="Play" click="Object('myVid'+videoRP.currentIndex.toString()).play();"/>

      But there still no working.

        • 1. Re: ID value in the loop
          QuickStick Level 1
          Hi,

          Try referencing it like an Array... VIDEO_ARRAY[0], VIDEO_ARRAY[1], VIDEO_ARRAY[2], etc.

          <mx:Button label="Play" click="Object('myVid'+VIDEO_ARRAY[0]).play();"/>

          or, maybe:

          <mx:Button label="Play" click="Object('myVid'+VIDEO_ARRAY[videoRP.currentIndex.toString()]).play();"/>

          Hopefully, either of those work for you.
          • 2. Re: ID value in the loop
            weiwuliang Level 1
            how about the ID name of the VideoDisplay?
            how to named it?
            As i named id="myVid{videoRP.currentIndex.toString()}"
            that is no working in my way? How to name it as well?
            • 3. Re: ID value in the loop
              QuickStick Level 1
              Same thing applies, reference the array again (VIDEO_ARRAY[0], VIDEO_ARRAY[1], VIDEO_ARRAY[2], etc.):

              id="myVid + VIDEO_ARRAY[0]"

              or:

              id="myVid + VIDEO_ARRAY[videoRP.currentIndex.toString()]"

              whichever worked the first time.

              It may need to be in () or {} brackets though...

              e.g:

              id="{myVid + VIDEO_ARRAY[0]}"

              or:

              id="{myVid + VIDEO_ARRAY[videoRP.currentIndex.toString()]}"

              Sorry I can't give you a definite answer.
              • 4. Re: ID value in the loop
                weiwuliang Level 1
                I have try in this way a lot of times looks like in the ID tag you can't pass the "{}" in!?
                eg:
                var IDnum:String = "A";

                then I try to named it few different way: for example
                (1) <mx:Label id="lbl{IDnum.toString()}" />
                (2) <mx:Label id="{'lbl'+IDnum.toString()}" />
                (3) <mx:Label id="{lbl+IDnum.toString()}" />

                looks like on the ID tag if i put "{}" in then it would not work!? is a BUG or what?



                • 5. Re: ID value in the loop
                  QuickStick Level 1
                  Sorry, a bit unsure about that.

                  Do you need to use an ID on the labels?

                  If you don't have to change the text of the labels, you shouldn't need an ID tag.
                  • 6. Re: ID value in the loop
                    QuickStick Level 1
                    However, if you do need to reference any of the labels (or repeated components) individually, you can use the array:

                    1. Name the component's ID (e.g. "lbl"):
                    <mx:Label id="lbl" />

                    2. You can then reference the repeated components, using:
                    lbl[0]
                    lbl[1]
                    lbl[2]
                    etc...
                    • 7. Re: ID value in the loop
                      weiwuliang Level 1
                      Ok got it. so now the code is working like this now:
                      <mx:Repeater id="videoRP" dataProvider="{VIDEO_ARRAY}">
                      <mx:VBox horizontalAlign="center" verticalAlign="middle" verticalGap="0" borderStyle="none" width="180" height="180">
                      <mx:VideoDisplay id="myVid" height="100" width="100" source="{videoRP.currentItem.source}" autoPlay="false"/>

                      <mx:HBox>
                      <mx:Button label="Play" click="myVid[videoRP.currentIndex].play();"/>
                      <mx:Button label="Pause" click="myVid[videoRP.currentIndex].pause();"/>
                      <mx:Button label="Stop" click="myVid[videoRP.currentIndex].stop();"/>
                      </mx:HBox>
                      </mx:VBox>
                      </mx:Repeater>

                      Thanks