本文共 1128 字,大约阅读时间需要 3 分钟。
//和C/C++的函数指针一样(函数回调),或者上升到object-c中的委托,Java中接口(面向接口的编程思想)
//在Flex或Actionscript中的控件事件监听,都是函数回调或函数指针的应用,举一反三,思想是一致的
//其中的一个类
private var _request:IRequestProxy;//一个接口
private var _handler:Function; private var _capabilities:IMapServerCapabilities;//一个接口public function set request(request:IRequestProxy):void{
this._request = request; _request.resultHandle = resultHandle; _request.faultHandle = faultHandle; } private function resultHandle(data:Object):void{ var capabilities:IMapServerCapabilities = new MapServerRestCapabilities(data,_request.url); this._capabilities = capabilities; if(_handler)//在此执行作为传入的实参的方法
_handler(capabilities);
}private function faultHandle(info:Object):void{
Alert.show(info.toString()); }public function loadCapabilities(handler:Function = null):void{
this._handler = handler; _request.request(HTTPRequestMessage.GET_METHOD); }//在另一个类中
public var baseMapServerProxy:IMapServerProxy;
//此方法 的参数会在调用此方法中赋值
private function baseMapServerLoadedHandle(capabilities:IMapServerCapabilities):void{
//执行代码 }baseMapServerProxy.loadCapabilities(baseMapServerLoadedHandle);//以方法名最为参数。此处没有参数,参数在调用此方法的方法中指定
转载地址:http://gdgab.baihongyu.com/