A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] accessing things in a namespace via []

  1. #1
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801

    resolved [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.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  3. #3
    Junior Member
    Join Date
    Aug 2008
    Posts
    26
    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 =)

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  5. #5
    Junior Member
    Join Date
    Aug 2008
    Posts
    26
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center