2 Replies Latest reply on Mar 9, 2010 11:39 PM by PDL_AGH

    reuse Repeater.currentItem value in a function

    PDL_AGH

      Hello everyone,

       

      I'm trying to reuse a value coming from a repeater to instantiate some variable. Could somebody please point me towards a solution for this?

       

      <pre>

                  <mx:Repeater id="rp"
                      dataProvider="{dataCollection.collection.resource}">
                          <mx:Label id="domains" height="24" width="150"
                              color="0x0B333C"
                              text="{String(rp.currentItem.@label)}"
                              click="domainDescriptionLoader(rp.currentItem.@label)" />
                  </mx:Repeater> 

      </pre>

       

      <pre>

                  private function domainDescriptionLoader(str:String):void {
                      docPath = str;
                      appendText(docPath);
                  } 

      </pre>

       

      All the best,

      Pierre

        • 1. Re: reuse Repeater.currentItem value in a function
          msakrejda Level 4

          In this case, you can use pass the event to the event handler for click and access its target (the repeated Label). The Label's text property will contain the label you're interested in. In general, you can use the repeater and repeaterIndex properties of UIComponent to find the corresponding item.

           

          More explicitly:

           

                      <mx:Repeater id="rp"
                          dataProvider="{dataCollection.collection.resource}">
                              <mx:Label id="domains" height="24" width="150"
                                  color="0x0B333C"
                                  text="{String(rp.currentItem.@label)}"
                                  click="handleClick(event)" />
                      </mx:Repeater>

           

                      private function handleClick(e:Event):void {

                          docPath = e.target.text;
                          appendText(docPath);
                      }

          1 person found this helpful
          • 2. Re: reuse Repeater.currentItem value in a function
            PDL_AGH Level 1

            Thanks for the quick and correct answer msakrejda. I also tried with the repeaterIndex (c.f. below) and both work.

             

                 docPath = labelDomains[event.currentTarget.repeaterIndex].text;
                 appendText(docPath);