Skip to content

Instantly share code, notes, and snippets.

@ryanguill
Last active December 14, 2015 19:29
Show Gist options
  • Save ryanguill/5137003 to your computer and use it in GitHub Desktop.
Save ryanguill/5137003 to your computer and use it in GitHub Desktop.
CFRemoteObjectFactory class - enables you to connect to any ColdFusion flex gateway without using compiler arguments. Much easier, lighter and more maintainable.
/*
// EXAMPLE USAGE
// copy this file to com/util/CFRemoteObjectFactory.as
import com.util.CFRemoteObjectFactory;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
[Bindable]
public var roMyRemoteObject:RemoteObject;
public var myCFRemoteObjectFactory:CFRemoteObjectFactory;
//doesnt have to be set up in the creationComplete, just wherever it makes sense.
public function creationComplete_event_handler ( e:FlexEvent ) : void
{
myCFRemoteObjectFactory = = new CFRemoteObjectFactory('http://localhost/flex2gateway/');
roMyRemoteObject = myCFRemoteObjectFactory.createRemoteObject('path.to.myCFC');
roMyRemoteObject.addEventListener(FaultEvent.FAULT,roMyRemoteObject_fault_handler);
roMyRemoteObject.doSomething.addEventListener(ResultEvent.RESULT,roMyRemoteObject_doSomething_result_handler);
roMyRemoteObject.doSomething('foo','bar');
}
public function roMyRemoteObject_fault_handler ( e:FaultEvent ) : void
{
Alert.show(e.fault.message);
}
public function roMyRemoteObject_doSomething_result_handler ( e:ResultEvent ) : void
{
Alert.show('Got a result');
}
*/
package com.utils
{
import mx.controls.Alert;
import mx.messaging.Channel;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.remoting.RemoteObject;
public class CFRemoteObjectFactory
{
private var _flexGateway:String;
public function CFRemoteObjectFactory(flexGateway:String)
{
_flexGateway = flexGateway;
}
public function set flexGateway ( value:String ) : void
{
_flexGateway = value;
}
public function get flexGateway () : String
{
return _flexGateway;
}
private function setUpAMFChannel ( ro:RemoteObject ) : RemoteObject
{
var amfChannel:Channel = new AMFChannel("my-cfamf",_flexGateway);
var amfChannelSet:ChannelSet = new ChannelSet();
amfChannelSet.addChannel(amfChannel);
ro.channelSet = amfChannelSet;
return ro;
}
public function createRemoteObject ( source:String ) : RemoteObject
{
var ro:RemoteObject = new RemoteObject('ColdFusion');
ro.source = source;
//trace(source);
//trace(_flexGateway);
return setUpAMFChannel(ro);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment