0

This is the code that does not work. The code required that I have the ID hard-coded in the checkbox tag.

<mx:HBox id="myHBox">
  <mx:Repeater id="checkBoxRepeater"
               dataProvider="{getItemsResult.lastResult}">
    <s:CheckBox label="{checkBoxRepeater.currentItem.itemName}"
                id="{checkBoxRepeater.currentItem.itemID}"/> <!--FB error here-->
  </mx:Repeater>
</mx:HBox>

If I type a string for id, I get my array of checkboxes without problem and the labels are all fine. I need to get the id dynamic so that I can send the ID (itemID) bound to an itemName to the server.

Any suggestions?

Shailen
  • 7,909
  • 3
  • 29
  • 37
  • I get this error `'{checkBoxRepeater.currentItem.itemID}' is not a valid identifier`. For sure, itemID is an integer, as can be observed in the datatype section of PHP services. – Shailen Jul 26 '11 at 16:37
  • duplicate? http://stackoverflow.com/questions/6832085/how-to-send-an-array-of-flex-checkboxes-to-a-mysql-server – michael Jul 26 '11 at 17:14
  • No, not duplicate. I asked the other question as well. The other question is how to actually send an array to the server. As it happens, it is not possible to create dynamic IDs, which really does not help in sending an array of IDs. – Shailen Jul 26 '11 at 22:22

1 Answers1

1

Ids are a compile-time concept, When a tag with an id is compiled the MXML compiler creates a reference variable in the component class that you're defining, that why there is no dynamic ids. Instead, you write and then access the repeated instances as checkBox[0], checkBox [1], etc.

<mx:Repeater ...>
   <s:CheckBox id="checkBox "/>
</mx:Repeater>
Laughingman
  • 136
  • 1
  • 7
  • Thank you for the response. Then regarding another question I asked (http://stackoverflow.com/questions/6832085/how-to-send-an-array-of-flex-checkboxes-to-a-mysql-server) how is it possible to send the id of the item, which in our case, would be the label of the checkbox, to the server? If you have any clue, please kindly reply on the other thread. Many thanks. – Shailen Jul 26 '11 at 22:20
  • Good hint. And then, for the changeHandler, I passed a second parameter called value, which is equal to `event.currentTarget.repeaterIndex` Code: `protected function checkbox_changeHandler(event:Event, value:int):void { if (checkbox[value].selected) { //do smthg } else { //do smthg else } trace(value); trace(checkbox[value].selected); }` – Shailen Jul 28 '11 at 04:55
  • Ok, for some unknown reasons, the code above is not being properly formatted. This much be of help to everybody else. – Shailen Jul 28 '11 at 04:59