Tutorial :getting mx:CheckBox values from inside mx:Repeater



Question:

I have an an array of objects that I use as the datasource for my repeater.

<mx:Repeater id="categoryRepeater" dataProvider="{this.allCategories}">  <mx:HBox>  <mx:Spacer width="20"/>  <mx:CheckBox id="categoryCheckBox" label="{categoryRepeater.currentItem.question}"/>  </mx:HBox>  </mx:Repeater>  

I would like to be able to tell which of the checkboxes in the list have been checked, but I'm not sure how to do it. I know I can add a function when it's clicked, but I don't know how to tell which checkbox called the function.


Solution:1

Use the currentIndex property.


Solution:2

I realize that this is a very old post, but I had run into the same issue and the currentIndex was not a sufficient answer for me. What I found to work better was to create a function on click:

<mx:Repeater id="rp" dataProvider="{dp}">    <s:CheckBox height="100%" width="100%" label="{String(rp.currentItem)}"    click="showAlert(event);"/>  </mx:Repeater>  

and the showAlert function looks something like this:

private function showAlert(evt:MouseEvent):void {    var curBox:CheckBox = evt.currentTarget as CheckBox;    var str:String = curBox.content.toString();    if(curBox.selected)      Alert.show(str + " clicked");  }  

This way you can deal with the event as a CheckBox inside of your ActionScript code and find values such as whether or not it has been selected etc.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »