-
[RESOLVED] accessing things in a namespace via []
No one's likely to answer this on this long weekend at 1 in the morning, but I'll ask anyway.
I'm trying to create a utility function package which uses introspection through describeType to get information about classes. Is there a way to get at properties/functions of an object using the [] operator if those properties are in a custom namespace?
Here's some code:
Main.as
Code:
...
public namespace madeup = "madeUp";
madeup function aMadeUpFunction(i:int, k:String, j:DisplayObject):String
{
return "hi!";
}
DescribeType node of that method:
Code:
<method name="aMadeUpFunction" declaredBy="Main" returnType="String" uri="madeUp">
<parameter index="1" type="int" optional="false"/>
<parameter index="2" type="String" optional="false"/>
<parameter index="3" type="flash.display::DisplayObject" optional="false"/>
</method>
Is there a way to do something like this?
Code:
var f:Function = obj['madeUp::aMadeUpFunction'];
Clearly, that doesn't actually work. I get this:
Code:
Error #1069: Property madeUp::aMadeUpFunction not found on Main and there is no default value.
obj is an instance of Main.
I saw http://troyworks.com/blog/2007/08/05...-of-namespace/ which looks like it's most of the way there, but I need to use an arbitrary namespace, not a predetermined one. I also don't seem to have access to the actual namespace through describeType, only the uri used to define it.
Also, I managed to crash the flex compiler with a NullPointer just now by doing this:
Code:
use namespace m.@uri.toString();
So, don't do that.
-
Senior Member
Have you tried including parentheses:
madeUp::aMadeUpFunction()
and may be even the function parameters?
I don't have any example to test that but it could be a possibility.
- The right of the People to create Flash movies shall not be infringed. -
-
Code:
var ns:Namespace = new Namespace(describeType(foo).method.@uri[0]);
var fn:String = describeType(foo).method.@name[0];
trace(foo.ns::[fn](1, "foo", this));
foo has a method aMadeUpFunction in namespace "madeUp", or it may be any other namespace for that case =) Hope it helps =)
-
wvxvw, that is exactly what I was looking for. How'd you figure out that syntax?
cancerinform, thanks, but I was actually looking for a reference to the function itself, not trying to invoke it.
I now have a utility class which can automagically expose methods to ExternalInterface via tagging. I'm going to clean up the code a bit and post a full write up in my blog and a link in the resource thread.
-
It's the same Namespace you use with XML, why would it behave differently with classes / functions? =)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|