The history of this problem stems way back from Flash Remoting in
ColdFusion 6.0.

ActionScript 1.0 APIs for Flash Remoting introduced "named arguments"
for CF-based invocation. The syntax for passing named arguments was
usually listed like this in documentation:

myCFService.cfFunction({var1:"foo",var2:"bar"});


Which was intended to match a CFC API:

<cffunction name="cfFunction" access="remote">
    <cfargument name="var1">
    <cfargument name="var2">
</cffunction>
 
The {} syntax, however, really just means an untyped Object, so this
invocation information is lost once it is serialized over AMF.

But AMF isn't the real issue - the Flash Remoting gateway can't adapt
accordinly as it can't get the necessary CFC API or argument type
information from the CFC function before invoking it (a limitation in
CF), so now it has a problem - how would it know that you're passing a
single struct or named arguments?

To disambiguate you use either of the two approaches that Mehdi
described.


-----Original Message-----
From: Mohanraj Jayaraman [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 25, 2005 2:12 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] How to pass AS Objects to a CFC


WOW! It works Mehdi. As you pointed out the second
variable passed in the CFC function call did the
magic! If possible, an explanation on why it works
with the second variable will be more useful Mehdi. 

My guess is that one should have good knowledge of
Flash/ActionScript before venturing into doing any
complex stuff with FLEX. 

Thanks a lot sharing this.

Mohanraj





--- "Mehdi, Agha" <[EMAIL PROTECTED]> wrote:

> Mohanraj,
> 
> I learned it the hard way. There are two ways to do
> it.
> 
> 1.
> Flex side:
> 
> var toPass = new MyClass();
> 
> toPass.var1 = "value";
> toPass.var2 = "value";
> 
> remoteObject.cfFunction ( toPass );
> 
> CF Side:
> 
> <cffunction name="cfFunction" access="remote">
>       <cfargument name="var1">
>       <cfargument name="var2">
> </cffunction>
> 
> I'm sure it's not acceptable.
> 
> 2.
> Flex Side:
> 
> var toPass = new MyClass();
> 
> toPass.var1 = "value";
> toPass.var2 = "value";
> 
> remoteObject.cfFunction ( toPass, true );
> 
> CF Side:
> 
> <cffunction name="cfFunction" access="remote">
>       <cfargument name="toPass">
> </cffunction>
> 
> That works beautifully. The second arg from Flex
> doesn't have to be a
> boolean but it just easy to type.
> 
> Please let me know if that works.
> 
> -----Original Message-----
> From: Mohanraj Jayaraman
> [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, March 24, 2005 10:37 AM
> To: flexcoders@yahoogroups.com
> Subject: RE: [flexcoders] How to pass AS Objects to
> a CFC
> 
> 
> Hi Dirk,
> 
> Thanks for your suggestion. But my condition differs
> from your example.
> 
> Lets assume I had an AS Class 'MyClass.as'
> I am trying to do something like this in my MXML
>   var o:Object = new MyClass();
>   I build an 'array of structures' in MyClass Object
> and I do pass the
> complex Object as input with another Object wrapper.
> 
> Here's an example by Macromedia on how exchange
> complex data
> 
>
http://www.macromedia.com/devnet/flex/articles/complex_data_03.html
> 
> According to macromedia
> When invoking methods remotely, you can pass objects
> back and forth (as the
> methods' input parameters and return value) between
> the client and the
> server.
> 
> This example is explained with Java and I am trying
> to replicate the same
> with Coldfusion CFC's.
> 
> Thanks,
> Mohanraj
> 
> 
> 
> --- Dirk Eismann <[EMAIL PROTECTED]>
> wrote:
> > Hi Mohanraj,
> > 
> > CF needs named parameters when dealing with
> complex types passed as 
> > CFC arguments. You have to wrap the object you
> want to send to the CFC 
> > into another wrapper object. Inside the wrapper
> you define properties 
> > for every named argument. This should
> > work:
> > 
> >   // AS snippet
> > 
> >   // setup the object to be passed to the CFC
> >   var o:Object = new Object();
> >   o.name = "Foo";
> >   o.date = new Date();
> >   o.otherData = [1,2,3,4,5];
> > 
> >   // create a wrapper for the object
> >   // input is the named argument of the CFC
> >   var request = new Object();
> >   request.input = o;
> > 
> >   // send it
> >   ro.sendComplexData(request);
> > 
> > The wrapper's "input" property is also used to
> identify the argument 
> > inside the CFC:
> > 
> >   <!--- CFC snippet --->
> >   <cffunction name="sendComplexData"
> access="remote"
> > returntype="string">
> >     <cfargument name="input" type="struct"
> > required="yes" >
> >     <cfreturn obj.name>
> >   </cffunction>
> > 
> > Dirk.
> > 
> > 
> > > -----Original Message-----
> > > From: Mohanraj Jayaraman
> > [mailto:[EMAIL PROTECTED]
> > > Sent: Thursday, March 24, 2005 3:12 AM
> > > To: flexcoders@yahoogroups.com
> > > Subject: Re: [flexcoders] How to pass AS Objects
> > to a CFC
> > > 
> > > 
> > > 
> > > Hi Clint,
> > > 
> > > Thanks for your reply. I think i was not clear
> > ealrier
> > > on my problem. Here's a sample code I am dealing
> > with.
> > > 
> > > Please note the property 'modarray' of the
> 'pData'
> > > object. 
> > > 
> > > 'modarray' is populated with SelTP object _s
> whcih
> > is
> > > an Array of Structures. Here I polupate the _s
> > with
> > > selectedIndices of a data gris I am using.
> > > 
> > > 
> > > The required parameter 'MODARRAY' not passed to
> > the
> > > function! is the message I get following my
> RemoteObject call
> > > 
> > > Any idea what I am missing here.
> > > 
> > 
> 
> 
>               
> __________________________________
> Do you Yahoo!? 
> Yahoo! Small Business - Try our new resources site!
> http://smallbusiness.yahoo.com/resources/ 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 
> 
> ----
> This email may contain confidential and privileged
> material for the sole use of the intended
> recipient(s). Any review, use, distribution or
> disclosure by others is strictly prohibited. If you
> are not the intended recipient (or authorized to
> receive for the recipient), please contact the
> sender by reply email and delete all copies of this
> message.
> 
> To reply to our email administrator directly, send
> an email to
> 
=== message truncated ===



                
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 


 
Yahoo! Groups Links



 





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to