本文转载自:http://hi.baidu.com/cdmember_daihw/blog/category/flash%20%D1%A7%CF%B0%B9%FD%B3%CC/index/1
有两种方法:
一个在按钮datagrid的itemRenderer写入的<mx:Script>
另外一个常用的方法,调用方法的时候在方法前加上outerDocument。就可以了
(ps: 调用外部的方法时候,注意,一定要用public修饰方法。)
<mx:Script>
<![CDATA[
//调用外部
publicfunction open():void{
Alert.show("调用外部的方法");
}
]]>
</mx:Script>
<mx:DataGrid id="dg" width="100%" height="70%" rowCount="10" textAlign="center">
<mx:columns>
<mx:DataGridColumn headerText="内部按钮" dataField="test1" >
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function open():void{
Alert.show("test");
}
]]>
</mx:Script>
<mx:Button label="选择指派人" click="open()" height="23" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="调用外部方法" dataField="ctrl" >
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center">
<mx:Button label="回收" click="outerDocument.open()" height="23" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
摘自:http://hi.baidu.com/henvy/blog/item/d43a73444edd2688b3b7dcb8.html