Thursday, April 17, 2008
Thursday, April 17, 2008    

I'm not really sure if something like this is very useful, but it does hide the guts of implementation away from a designer.

Basically it's a class abstracting describeType a little bit more so a designer doesn't need to look at the E4X stuff and get spooked by it. They don't even have to know about describeType at all.

package
{
  import flash.utils.describeType;
  public class TypeDescriptor
  {
  public function TypeDescriptor()
  {
  }
  public function getTypeName( value:* ):String
  {
  var varList:XML = describeType( value );
  var result:String = varList.@name.toXMLString();
  return( result );
  }
    }
}

And the usage is pretty simple:

import TypeDescriptor;
var foo:TypeDescriptor = new TypeDescriptor();
trace( foo.getTypeName( ["hello", "sup"] )); //Array
trace( foo.getTypeName( 5 ) ); //int
trace( foo.getTypeName( "hello" ) ); //String
trace( foo.getTypeName( new MovieClip() ) ); //flash.display::MovieClip
trace( foo.getTypeName( JessicaAlba ) ); //JessicaAlba (class from IDE & instantiated in the class itself)
trace( foo.getTypeName( this ) ); //if in a class (Application), something like com.ericd.projectOne::Application

Again, not very useful for developers perhaps, but it makes life easier on a designer. And I suppose you could add methods to retrieve different parts of the XML (base, isDynamic, isFinal, isStatic, etc.)


0 Comments:

Post comment

Links to this post:


Create a Link

gotoAndStop( topOfPage );