Prana 0.2 released with AS3 Reflection API

ActionScript, Flash, Flex, Prana Add comments

I just managed to release a new version of the Prana Framework. The new release contains an AS3 Reflection API and some general updates.

Reflection API

A quick example of the Reflection API:

Actionscript:
  1. var instance:MyClass = new com.domain.MyClass();
  2.  
  3. // get the type info of the instance variable
  4. var type:Type = Type.forInstance(instance);
  5. // ... or via the class object
  6. //var type:Type = Type.forClass(MyClass);
  7. // ... or via the class name
  8. //var type:Type = Type.forName("MyClass");
  9.  
  10. // we now have access to the properties and methods
  11. // defined by the MyClass class
  12. trace(type.name); // outputs "MyClass"
  13. trace(type.fullName); // outputs "com.domain::MyClass"
  14. trace(type.methods);
  15. trace(type.staticConstants);
  16. trace(type.staticVariables);
  17. trace(type.constants);
  18. trace(type.variables);
  19. // ... and lots more
  20.  
  21. // it is also possible to dynamically invoke methods
  22. var result:* = type.methods[0].invoke(instance, arg1, arg2);

General info and downloads

New Developer for Prana

Other news is that my co-worker Kristof "Hickey" Neirynck has joined the development team. Welcome Kristof!

Hope you enjoy it! As usual, any feedback is kindly appreciated.


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

5 Responses to “Prana 0.2 released with AS3 Reflection API”

  1. michal kuklis Says:

    thanks
    great work. I will play with it over the weekend

    cheers!

  2. Artemy Says:

    Hello. Could you give a hint of library reflection. I.e. how can I programmatically find out which classes are included in SWC or application. I’d like to have a list of classes like [”com.example.flex:MyClass”, “com.example.flex:MyClass2″, …]
    Thank you for ideas!

  3. Adam Says:

    Hi, How far did you get with your mock testing framework? I am playing with the idea of implementing a mock object framework in AS3.

  4. Keith Says:

    Hello,

    How can I accomplish in AS the java equivalent of below? I want to dynamically invoke a method:

    Class c = IncidentRules.class;
    Class[] parameterTypes = null;
    Method methodName;

    methodName = c.getMethod(”validate”+commandName,parameterTypes);
    methodName.setAccessible(true);
    methodName.invoke(this,null);

  5. Erik Westra Says:

    In AS3 you can use [ and ] to accomplish that:

    c[”validate” + commandName]();

    or:

    methodReference = c[”validate” + commandName];
    methodReference();

    or:

    methodReference.apply(null, []);

    or:

    methodReference.call(null);

    Greetz Erik

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login