<mx:VBoxxmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="50" implements="mx.controls.listClasses.IDropInListItemRenderer"> <mx:Script> <![CDATA[ import mx.controls.DataGrid; import mx.controls.List; import mx.controls.dataGridClasses.DataGridColumn; import mx.controls.listClasses.BaseListData; // store the list data item in case we want to do something with it // later on privatevar _listData:BaseListData; [Bindable("dataChange")] // a getter method. publicfunction get listData():BaseListData { return _listData; } // a setter method,当BaseListData 数据被传入之后renderer 就可以通过它自己的一 //些属性访问拥有它的父组件中元素的数据,甚至可以调用父组件中的方法。 publicfunction set listData(value:BaseListData):void { _listData = value; if (value.owner is DataGridColumn) { trace("DataGridColumn"); } elseif(value.owner is List) { trace("List"); } elseif (value.owner is CustomDataGrid) { trace("CustomDataGrid"); (value.owner as CustomDataGrid).checkInMethod(this); } } override publicfunction set data(value:Object):void { nameTxt.text = value.name; appearanceTxt.text = value.appearance; }
<mx:HBoxxmlns:mx="http://www.adobe.com/2006/mxml" xmlns:cookbook="oreilly.cookbook.*"> <mx:ListitemRenderer="oreilly.cookbook.IDropInListRenderer" dataProvider="{DataHolder.genericCollectionOne}"/> <!-- note that creating a custom component with a new namespace, cookbook, requires that our columns are declared w/in the cookbook namespace --> <cookbook:CustomDataGrid dataProvider="{DataHolder.genericCollectionOne}"> <cookbook:columns> <!-- since we're not declaring a dataField, the entire data object is passed to the renderer --> <mx:DataGridColumn itemRenderer="oreilly.cookbook.IDropInListRenderer"/> <mx:DataGridColumndataField="age"/> </cookbook:columns> </cookbook:CustomDataGrid> </mx:HBox>