Expand my Community achievements bar.

Passing Objects into CFCs using RemoteObject

Avatar

Level 2
I have many RemoteObject calls in my project which pass
strings and other simple data types into cfcs, however this is the
first time I have tried to pass in a Flex Object.



svc.myMethod(myObject);



If I set up myObject as an identical looking structure in
test.cfm and run it, myCFC (which has a single argument myArg of
type struct) returns the correct data.



But when I pass in myObject from Flex, I get a service error:



The parameter myArg to function myMethod is required but was
not passed in.



Is there something else I need to do if I pass in an Object??



Doug
5 Replies

Avatar

Level 2
I've ran into this as well and it's definitely a bug. If a
CFC method accepts one struct argument, you will get this error. If
you give the CFC method a second dummy argument and just pass junk
to it, it works fine. Go figure.

Avatar

Level 1
Actually it's not a bug, it's more of a side effect of
supporting attributeCollection and optional CFC arguments from
flash.



In flash, you can call a function 2 ways

parameter list (args must be in a specific order)

myRemoteObject.myFunction(val1, val2, val3);

or a named list (and args can be in any order, lets you
define optional arguments)

myRemoteObject.myFunction( {arg1:val1, arg3:val3, arg2:val2}
);



However the side effect is

myFunction( someObject );

and

myFunction( {arg1:val1, arg2:val2} );



both appear to CF as 1 argument that is a struct. So if you
are only passing 1 argument, CF assumes you are trying to use named
arguments so it tries to map all of the properties to individual
arguments and it will pass all of the properties in as individual
arguments.



However, if you pass a 2nd argument in then CF knows the
first argument is a struct and passes it into the cfc function as a
struct.



So your workaround is to pass in a 2nd argument with the
function call. And the easiest way to do this is to pass null as
the 2nd arg. This way the Flash Remoting gateway will see 2 args
but since CF doesn't understand null it will ignore it.



myRemoteObject.myFunction( someObject, null );



hth,

---nimer

Avatar

Level 2
You're right! Weird.



Thanks,



Doug

Avatar

Level 2
Ok, that makes sense. And now that you mention it, I remember
this from the old Flash Remoting days. But is this mentioned
anywhere in the Flex 2 docs? It's a very obscure error message for
something like this.

Avatar

Level 2
can someone show me a sample. I have been working on this for
weeks with no outcome. I have changed the 4 spots in the wrapper I
have my RemoteObject supposedly sending my argument SupplierID. I
added what would result in null another argument BrandID. But non
of this works. Why no docs and few posts, am I one of the very few
people trying such a thing or is everyone doing this with no
trouble. I needed this to work weeks ago. I seem to get a tiny bit
of info with each post but no go. yet