Thank you, very interesting.
Now since the callee would typically be a Flex based UI control describeType
might be a bit heavy (yes/no?).
I am basically trying to wrap RemoteObject calls and automatically instantiate
a typed ArrayCollection (since remote object will always be Array or
ArrayCollection) when the result comes back; I only do this for collection
based results. I don't think any code generation is necessary if I can get away
with runtime introspection.
Right now I have to manually specify what type of collection the callback might
expect but this would remove a potential point of error.
On my event.result listener in my RO wrapper I basically have
function getRemoteBusinessObjectsWrapper(someParameters:String,
myCallbackFunction:Function) : void
{
myRoWrapper("RemoteMethodName", myCallbackFunction, ArrayOfCustomObjects /*
this is the type */);
}
I would like to simply this to:
myRoWrapper(myCallbackFunction)
Assuming that remote function name is identical to my flex wrapper and can be
gotten via runtime introspection.
-------------------------------------------------------------
function roCallback(event:ResultEvent, collectionType:Class)
if(event.result is IList)
callbackFunction(new collectionType(event.result.toArray()));
---------------------------------------------------------------------
function myCallbackFunction(result:ArrayOfCustomObjects ) {}
Does this make sense? Since this is a infrequent remote call I would think the
describeType overhead might be justified.
-Tomek (http://tomek.me)
--- In [email protected], Oleg Sivokon <olegsivo...@...> wrote:
>
> Just adding to what Alex said: parameters' names don't exist in compiled
> SWF, they are referenced by indices (when the function starts, the
> parameters are pushed to the stack and just follow the stack logic). So, no,
> reflection can only tell you the number of parameters used (you can get it
> from myFunction.length property), but the names simply don't exist.
>
> Regarding the function name, if it's a public / protected / internal /
> custom namespace method, you can get it through describeType() if you call
> it on the object, where the function belongs to, and then compare it like
> so:
>
> var s:Sprite = new Sprite();
> var list:XMLList = describeType(s).meth...@name;
> var f:Function = s.addChild;
> list.(s[valueOf().toString()] == f && trace("method found",
> valueOf().toString())); //method found addChild
>
> However, anonymous functions do not have names (the names of anonymous
> functions are generated dynamically following a pattern), also, it's not
> always possible to get the name of functions which are declared as
> variables.
>
> Another way of retrieving this info is by parsing the assembly (the DoABC
> tag), even the release builds contain the function method, but this is a bit
> complex, and, I don't think that it would be worth the effort,
> unless retrieving the function's name is the purpose of your application.
>
> Best.
>
> Oleg
>