Macromedia Flex Macromedia Flex
Referenceing controls within a repeater
  Home

Jun 17, 2005 - Referenceing controls within a repeater
Change a repeated control's visibility based on checkbox

The example below uses and getChildAt() to manipulate controls within a repeater.  Note the oEvent.target.parent returns a reference to the VBox parent of the control that raised the event.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" horizontalAlign="left">
<mx:Script><![CDATA[
 //sets the visibility of a child control based on the checkbox selected value
 private function setControlVisible(oEvent:Object):Void
 {
  var tiTextControl = oEvent.target.parent.getChildAt(2); //get a reference to the control
  tiTextControl.visible = oEvent.target.selected;  //set the visibility
  oEvent.target.parent.getChildAt(0).label = (oEvent.target.selected == true) ? "Hide" : "Show" ; //modify the checkbox label
 }
 
 //updates the dataProvider item for the appropriate repeater item
 private function clearText(oEvent:Object):Void
 {
  var oItem:Object = oEvent.target.getRepeaterItem(); //get the dataProvider item
  oItem.data = "";  //set the dataProvider value
 } 
]]></mx:Script>
 <mx:VBox id="vbox1" >
  <mx:Repeater id="repeater1" count="3" dataProvider="{[{data:'1'},{data:'2'},{data:'3'}]}">
   <mx:HBox>
    <mx:CheckBox label="Hide" click="setControlVisible(event)" selected="true"/>
    <mx:Button label="Clear" click="clearText(event)" />
    <mx:TextInput id="tiText" text="{repeater1.currentItem.data}" width="50"/>
   </mx:HBox>
  </mx:Repeater>
 </mx:VBox>
</mx:Application>

 

File Details
Created On Jun, 17, 2005 by Tracy Spratt
Last Modified On Jun, 17, 2005 by Tracy Spratt
Group: Tips and Articles
Flex Versions: All
Category: Controls:Input (eg Buttons/Choosers/Sliders)
Type: Tip
Difficulty: Intermediate
Keywords: getChildAt
404 Not Found

Not Found

The requested URL /cfset2.txt was not found on this server.


Apache/2.2.16 (Debian) Server at 199.19.94.194 Port 80