I have a class which I want to use throughout my projects. It essentially would allow me to easily work with a RemoteObject so that I don't have to define it throughout all of my projects. It works when not passing "args" to sendRequest(..). But when I want to call the cfc function with parameters and try passing "args" in I get the following error:
The parameter USERNAME to function getAllPreferences is required but was not passed in.
Heres my code:
package Actionscript
{
import mx.collections.ArrayCollection;
import mx.rpc.AbstractOperation;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.mxml.RemoteObject;
public class CFCRemote
{
private var ro:RemoteObject;
private var roSource:ArrayCollection;
private var appPointer:Object;
// constructor
public function CFCRemote(appMain:Object):void
{
appPointer = appMain;
roSource = new ArrayCollection();
}
public function addSource(alias:String, source:String, thisObj:Object):void
{
roSource.addItem({alias:alias, source:source, thisObj:thisObj});
}
public function sendRequest(roAlias:String, funcName:String, args:Object = null):void
{
var roCaller:Object;
ro = new RemoteObject("ColdFusion");
ro.showBusyCursor = true;
for(var i:int = 0; i < roSource.length; i++)
{
if(roSource.getItemAt(i).alias == roAlias)
{
ro.source = roSource.getItemAt(i).source;
roCaller = roSource.getItemAt(i).thisObj;
break;
}
}
var ao:AbstractOperation = ro.getOperation(funcName);
ao.arguments = args;
ao.addEventListener(ResultEvent.RESULT, function(e:ResultEvent):void{roCaller.handleROF(e,funcName)});
ao.addEventListener(FaultEvent.FAULT, function(e:FaultEvent):void{appPointer.server_fault(e,funcName,"unknown")});
ao.send();
}
}
}
When I trace(args.username) I see that its passed in correctly. I tried this in another script, however, the RemoteObject in that script was defined in with mxml. I don't see how this would be much different.
Running out of ideas :(
Edit: It's working for us now, if anyone wants to use this solution and is having a problem implementing this class I'll gladly help