flex Renderer中获取父对象 博客分类: Flex flexrenderer父对象
要在渲染器中获得其父对象,通过实现IDropInListItemRenderer实现(以DataGrid为例)
1、在渲染器中实现IDropInListItemRenderer接口
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true"
implements="mx.controls.listClasses.IDropInListItemRenderer">
</s:MXDataGridItemRenderer>
2、实现接口的方法,通过此获得父对象
private var _listData:BaseListData;
private var _owner:DataGrid = null; //父对象
[Bindable("dataChange")]
override public function get listData():BaseListData { return _listData; }
override public function set listData(value:BaseListData):void {
_listData = value;
_owner = value.owner as DataGrid;
}
3、在此基础上可以取得最顶层文档对象(文档对象是位于 Flex 应用程序、MXML 组件或 AS 组件层次结构顶层的 UIComponent)