This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
RemoteDelegate Class | |
Copyright (c) 2009 Simon Bailey <simon@newtriks.com> | |
Your reuse is governed by the Creative Commons Attribution 3.0 License | |
*/ | |
package | |
{ | |
import mx.rpc.AsyncToken; | |
import mx.rpc.IResponder; | |
import mx.rpc.remoting.RemoteObject; | |
import mx.utils.*; | |
import flash.utils.*; | |
public class RemoteDelegate | |
{ | |
private var responder:IResponder; | |
private var ro:RemoteObject; | |
public function RemoteDelegate( responder:IResponder, url:String ) | |
{ | |
ro = new RemoteObject(); | |
ro.destination = "ColdFusion"; | |
ro.source = url; | |
// and store a reference to the proxy that created this delegate | |
this.responder = responder; | |
} | |
public function call( method:String, ...args ):void | |
{ | |
var token:AsyncToken; | |
// Call the service | |
token = applyMethod( ro, method, args ); | |
// Notify this responder when the service call completes | |
token.addResponder( this.responder ); | |
} | |
public static function applyMethod( obj:*, name:String, argArray:Array = null ):* | |
{ | |
if( obj is flash.utils.Proxy ) | |
{ | |
var args:Array = [name]; | |
if( argArray != null && argArray.length > 0 ) args["push"].apply( args, argArray ); | |
return flash.utils.Proxy( obj ).flash_proxy::callProperty.apply( obj, args ); | |
} | |
else return obj[name].apply( obj, argArray ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment