Apache flex 从Flex 3中的组件调用外部方法

Apache flex 从Flex 3中的组件调用外部方法,apache-flex,datagrid,itemrenderer,linkbutton,Apache Flex,Datagrid,Itemrenderer,Linkbutton,我创建了一个应用程序来显示Flex3中带有自定义列的datagrid。 如何访问此代码中的loadDetails方法 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ public function loadDetails(id:String) : void { // S

我创建了一个应用程序来显示Flex3中带有自定义列的
datagrid
。 如何访问此代码中的loadDetails方法

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
     <mx:Script>
        <![CDATA[
            public function loadDetails(id:String) : void { // Some code here 
                    }
        ]]>
    </mx:Script>
    <mx:DataGrid dataProvider="{[{id:'123456',name:'',address:''}]}">
    <mx:columns>
    <mx:DataGridColumn headerText="Serial" dataField="id"/>
        <mx:DataGridColumn headerText="Cliente" dataField="name"/>
        <mx:DataGridColumn headerText="Dirección" dataField="address"/>
        <mx:DataGridColumn width="50" dataField="id" headerText="">
            <mx:itemRenderer>
                <mx:Component>
                <mx:LinkButton label="" toolTip="Details" icon="@Embed('../resources/icons/details.png')" click="loadDetails(data.id);">
                    </mx:LinkButton>
                </mx:Component>
        </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>
    </mx:DataGrid>
</mx:Application>


当我试图运行这段代码时,Flex抛出了一个错误。它说loadDetails没有定义。我想这个错误是因为范围。但是我不知道如何解决它。

组件标记中的任何内容基本上都是组件工厂的描述符。因此,该标记内的任何内容都将在本地范围内。但是,您可以使用属性outerDocument(如果我没记错的话)访问该itemRenderer所在的文档

<mx:LinkButton label="" toolTip="Details" icon="@Embed('../resources/icons/details.png')" click="outerDocument.loadDetails(data.id);"/>


或使用冒泡事件向表单(或其他地方)上的侦听器发出您要执行的操作的信号。

确定。。我正在学习flex,现在我不知道该怎么办。。我试过了,效果很好!!。。谢谢……)