2 Replies Latest reply on Sep 19, 2008 10:16 AM by Newsgroup_User

    How to get id of button in repeater component

    Borisv28-jPMNU2
      I want to get or set an id of button in repeater component:

      <mx:Repeater id="repeaterData" dataProvider="{xmldata.lastResult.names.name}">
      <mx:Button label="{repeaterData.currentItem}" id="{repeaterData.currentIndex}"/>
      </mx:Repeater>


      id="{repeaterData.currentIndex}" does not work because currentIndex returns int value.

      Please, is there a possible way to get id?
        • 1. Re: How to get id of button in repeater component
          Level 7

          "Borooooon" <webforumsuser@macromedia.com> wrote in message
          news:gb0lqj$r5n$1@forums.macromedia.com...
          >I want to get or set an id of button in repeater component:
          >
          > <mx:Repeater id="repeaterData"
          > dataProvider="{xmldata.lastResult.names.name}">
          > <mx:Button label="{repeaterData.currentItem}"
          > id="{repeaterData.currentIndex}"/>
          > </mx:Repeater>
          >
          >
          > id="{repeaterData.currentIndex}" does not work because currentIndex
          > returns
          > int value.
          >
          > Please, is there a possible way to get id?
          >

          Q: I'm using a Repeater to lay out the right number of components on
          the screen for me based on a data source. I'm trying to set up the id for
          each component dynamically like this:

          <mx:Repeater id="myRepeater" dataProvider="mySource">
          <mx:Button id="{'myButton'+myRepeater.currentIndex}"
          label="{myRepeater.currentItem.label}" />
          </mx:Repeater>

          When I try to run the file, I get a compiler error
          '{'myButton'+myRepeater.currentIndex}' is not a valid identifier.

          I need to be able to reference each of the repeated components. How can I
          do this?



          A: If you give the component an ordinary id like this:
          <mx:Button id="myButton" label="{myRepeater.currentItem.label}" />
          Flex will create an Array for you called myButton that contains a reference
          to each component the repeater created. For more information, see
          Referencing Created Components here:
          http://livedocs.adobe.com/flex/3/html/help.html?content=repeater_3.html

          From Amy's Flex FAQ. This FAQ gets posted weekly, and the latest version of
          this FAQ is always available here (it just so happens this Q was added this
          week, so it was not posted this Modnay):

          http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf


          • 2. Re: How to get id of button in repeater component
            Level 7

            "Amy Blankenship" <amySpamFilter@magnolia_pleaseNOspam_multimedia.com> wrote
            in message news:gb0mh3$rvg$1@forums.macromedia.com...
            >
            > "Borooooon" <webforumsuser@macromedia.com> wrote in message
            > news:gb0lqj$r5n$1@forums.macromedia.com...
            >>I want to get or set an id of button in repeater component:
            >>
            >> <mx:Repeater id="repeaterData"
            >> dataProvider="{xmldata.lastResult.names.name}">
            >> <mx:Button label="{repeaterData.currentItem}"
            >> id="{repeaterData.currentIndex}"/>
            >> </mx:Repeater>
            >>
            >>
            >> id="{repeaterData.currentIndex}" does not work because currentIndex
            >> returns
            >> int value.
            >>
            >> Please, is there a possible way to get id?
            >>
            >
            > Q: I'm using a Repeater to lay out the right number of components
            > on the screen for me based on a data source. I'm trying to set up the id
            > for each component dynamically like this:
            >
            > <mx:Repeater id="myRepeater" dataProvider="mySource">
            > <mx:Button id="{'myButton'+myRepeater.currentIndex}"
            > label="{myRepeater.currentItem.label}" />
            > </mx:Repeater>
            >
            > When I try to run the file, I get a compiler error
            > '{'myButton'+myRepeater.currentIndex}' is not a valid identifier.
            >
            > I need to be able to reference each of the repeated components. How can I
            > do this?
            >
            >
            >
            > A: If you give the component an ordinary id like this:
            > <mx:Button id="myButton" label="{myRepeater.currentItem.label}" />
            > Flex will create an Array for you called myButton that contains a
            > reference to each component the repeater created. For more information,
            > see Referencing Created Components here:
            > http://livedocs.adobe.com/flex/3/html/help.html?content=repeater_3.html
            >
            > From Amy's Flex FAQ. This FAQ gets posted weekly, and the latest version
            > of this FAQ is always available here (it just so happens this Q was added
            > this week, so it was not posted this Modnay):
            >
            > http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf

            Correction: that should be "Referencing Repeated Components".

            HTH;

            Amy