Warning: include() [function.include]: Unable to access /var/www/html/rogue-development/blog2/wp-content/advanced-cache.php in /var/www/html/rogue-development/blog2/wp-settings.php on line 62

Warning: include(/var/www/html/rogue-development/blog2/wp-content/advanced-cache.php) [function.include]: failed to open stream: No such file or directory in /var/www/html/rogue-development/blog2/wp-settings.php on line 62

Warning: include() [function.include]: Failed opening '/var/www/html/rogue-development/blog2/wp-content/advanced-cache.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/rogue-development/blog2/wp-settings.php on line 62

Notice: add_option was called with an argument that is deprecated since version 2.3 with no alternative available. in /var/www/html/rogue-development/blog2/wp-includes/functions.php on line 3468

Notice: register_sidebar_widget is deprecated since version 2.8! Use wp_register_sidebar_widget() instead. in /var/www/html/rogue-development/blog2/wp-includes/functions.php on line 3382

Notice: register_widget_control is deprecated since version 2.8! Use wp_register_widget_control() instead. in /var/www/html/rogue-development/blog2/wp-includes/functions.php on line 3382
Easy object reflection with Spicelib « Marc’s Musings

Easy object reflection with Spicelib

I use Parsely in some of my projects for an MVC / IoC framework.  Parsley relies on Spicelib, so you get that functionality “for free” if you’re using Parsley.  Lately, I’ve started using some of the Spicelib relflection API and I’m impressed with it.  It acts as a wrapper around the flash.utils.describeType method to describe objects at runtime.

Here’s an example that loops through the properties of an object…

  1. var ci:ClassInfo = ClassInfo.forInstance( component );
  2. for each ( var property:Property in ci.getProperties() )
  3. {
  4.   trace( property.name );
  5.   trace(property.type.name );
  6.   trace( property.readable );
  7.   trace( property.writable );
  8. }

You can get a whole lot of info about classes, methods, and properties, you can read the docs to see.

One useful function of this, is you can get at any custom metadata tags that you’ve created.  In that loop above, I could have something like this:

  1. for each ( var meta:Metadata in property.getAllMetadata() )
  2. {
  3.   if( meta.name == "AnimationProperty" )
  4.   {
  5.     // do something with this property
  6.   }
  7. }

Then, if I had a class like this:

  1. public class StupidClass
  2. {
  3.     [AnimationProperty]
  4.     public var thisIsAnAnimationProperty:Number;
  5.  
  6.     public var thisIsNOTAnAnimationProperty:Number;
  7. }

We could differentiate between those two properties.

Read this blog entry for a little info on how to do custom metadata.

0 Responses to “Easy object reflection with Spicelib”


Comments are currently closed.