Skip to content

Instantly share code, notes, and snippets.

@newtriks
Created November 8, 2011 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newtriks/1347662 to your computer and use it in GitHub Desktop.
Save newtriks/1347662 to your computer and use it in GitHub Desktop.
/*
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