2 Replies Latest reply on Jan 13, 2007 9:42 AM by BaileyBurger

    How to return currentIndex from repeater

    BaileyBurger
      Greetings,

      How can I return the currentIndex from a repeater on a button click, as in:

      <mx:Repeater id="Playlist" dataProvider="{MySongList}">
      <mx:Label text="{Playlist.currentItem.TITLE}"/>
      <mx:Button label="x" click="Alert.show(String(Playlist.currentIndex));"/>
      </mx:Repeater>

      Thanks!!!
        • 1. How to return currentIndex from repeater
          Hugo_Core Level 1
          Hi BaileyBurger,

          Does this sample code help ?

          <?xml version="1.0"?>
          <!-- Simple example to demonstrate the Repeater class. -->
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

          <mx:Script>
          <![CDATA[

          import mx.controls.Alert;

          [Bindable]
          private var dp:Array = [1, 2, 3, 4, 5, 6, 7, 8, 9];

          ]]>
          </mx:Script>

          <mx:Panel title="Repeater Example" width="75%" height="75%"
          paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

          <mx:Text width="100%" color="blue"
          text="Use the Repeater class to create 9 Button controls in a 3 by 3 Tile container."/>

          <mx:Tile direction="horizontal" borderStyle="inset"
          horizontalGap="10" verticalGap="15"
          paddingLeft="10" paddingTop="10" paddingBottom="10" paddingRight="10">

          <mx:Repeater id="rp" dataProvider="{dp}">
          <mx:Button height="49" width="50"
          label="{String(rp.currentItem)}"
          click=" Alert.show(String(event.currentTarget.getRepeaterItem()) + ' pressed')"/>
          </mx:Repeater>
          </mx:Tile>

          </mx:Panel>
          </mx:Application>
          • 2. Re: How to return currentIndex from repeater
            BaileyBurger Level 1
            Example shows currentTarget. I'm looking for currentIndex.

            My repeater is built off an array, and the button click triggers a splice to remove the selected index out of that array. I could place the array # into the array itself, then return it as currentTarget, but seems a pain to manage that if I could just allow the array to manage itself.

            The best result I could get was:
            <mx:Button label="x" data="{Playlist.currentIndex+1}" click="RemoveSong(event.currentTarget.data);"...

            I had to bump the currentIndex + 1 as a 0 return object.object. This works, but I'm not feeling good about it.