3 Replies Latest reply on Sep 20, 2007 4:16 PM by Senor_Roberto

    Self Reference

      I'm using a repeater and have need to know which of it's children is being clicked. How do you do that in Flex?
        • 1. Re: Self Reference
          Can you post some MXML of your repeater?

          The event.target should tell you which object it was dispatched from.
          • 2. Re: Self Reference
            SynthesisMod Level 1
            Hi Senor Roberto, thanks for responding to my post. This is my first Flex app and I'm still trying to wrap my mind around it. I appreciate the help.

            I tried event.target and it did bring me closer to what I need to do. However, it returns exactly what you clicked in. Sometimes it returns a child element when what I need is the componenent itself. Is there a way to filter that?

            Here is my sample code of the repeater, a function for testing event.target, and the trace output from the console:

            ----- Repeater Code -----

            <mx:Repeater id="productRepeater" dataProvider="{searchData}">
            <comp:ProductTile addedEffect="transition1" id="productTile" click="showClick(event.target)"
            productCapHigh="{productRepeater.currentItem.search.capacity.high}" />

            ----- Function for testing return of "event.target" -----

            public function showClick(whatClick:Object):void

            ----- Console Output from trace(whatClick) -----



            What I need returned ever time is the id of the component, productTile[1], productTile[2], etc.

            Thanks again for the help,

            • 3. Re: Self Reference
              Senor_Roberto Level 1
              When you say you need the id of the component, do you mean index?

              You can't have an id property on a component inside a repeater since there's more than one, but you can have one in the dataProvider object which backs it.

              I've just looked at the documentation (I know, crazy) and I think you should try:


              This will return you the Object in the dataProvider of the repeater corresponding to the component you clicked. You can take any property you want off it, including an internal id.

              If you don't want the id but actually want the index, you need to set it when the repeater is initialised. In your example, you would add a new property to your ProductTile compponent called productIndex (or similar). Then in your MXML you would have:

              <comp:ProductTile ...productIndex="{productRepeater.currentIndex}"...

              This would inject the index of the repeater into your component when the repeater initialises. In the click handler you could then do this:


              And get the index of the repeater which was clicked.