2/24/2011 11:06:13 PM
Title:
item renderer in Flex 4
How I will get reference of object which has been added via item renderer.
Suppose I have added a custom component [which include a check box ] in display list via item renderer.
Now i want get the current status of the check box inside the custom component, whether it is selected or not.How I will do that.
2/25/2011 11:07:38 AM
I think this example will help you . Here we are making a textbox editable true or false depending upon the checkbox in datagrid
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] private var users:ArrayCollection = new ArrayCollection();
private function init():void {
users = new ArrayCollection(myData.person);
}
public var abc="cdf";
public function changeText(event:MouseEvent):void{
if(event.target.selected == true){
//checkbox selected then edit cilum 2 and row
myDataGrid.editable=true;
myDataGrid.editedItemPosition = {columnIndex:1, rowIndex:myDataGrid.selectedIndex};
}else{
//clear editable field when checkbox not selected
myDataGrid.editable=false;
}
}
]]>
</mx:Script>
<mx:Model id="myData">
<users>
<person>
<name>Data1</name>
<address>Address1</address>
</person>
<person>
<name>Data2</name>
<address>Address2</address>
</person>
<person>
<name>Data3</name>
<address>Address3</address>
</person>
</users>
</mx:Model>
<mx:DataGrid id="myDataGrid" dataProvider="{users}" initialize="{Application.application.abc=myDataGrid;trace(Application.application.abc)}" rowCount="5" width="300" height="200" editable="true" >
<mx:columns>
<mx:DataGridColumn headerText="Name" width="100" dataField="name" editable="false" editorDataField="text" />
<mx:DataGridColumn headerText="Addresss" dataField="address" width="200" editable="true" />
<mx:DataGridColumn headerText="CheckBox">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox label="Change" click="outerDocument.changeText(event)" />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>