Question

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

Was it helpful?

Solution

Trying passing the arguments to AbstractOperation.send() rather than setting them on the AbstractOperation. I haven't tried the latter before but I've passed them to the send() method more times that I can count without problems. You may want to consider passing the args using "... args" or as an Array/ArrayCollection to ensure you maintain the order.

OTHER TIPS

Well I can't say I know Flex terribly well, but the fact that you're instantiating an abstract class does throw up some red flags for me. Usually you never directly instantiate abstract classes - instead they are used as base classes for the classes you actually do instantiate.

In this case I think you are looking for the Operation class. If that's the case then you may also need to provide it with an "argumentNames" array - this seems to provide the order in which your arguments should be passed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top