package com.ericfeminella.utils
{
import flash.utils.getDefinitionByName;
/**
*
* Returns the class Object based on the String name
* representation
*
* @see flash.utils.getDefinitionByName
*
*/
public class Reflection
{
/**
*
* Returns the class Object for the String name representation
* specified in the type parameter.
*
* <p>
* Keep in mind that you will always need an internal reference
* to the class that is passed to <code>getType();</code>
* </p>
*
* <p>
* For instance, the following code below will throw an error if
* there is not an instance of a DataGrid defined previously:
* </p>
*
* @example
* <listing version="3.0">
*
* var ClassReference:Class = Reflection.getType("mx.controls.DataGrid");
* var dataGrid:* = new ClassReference();
* //throws an exception since Flash Player does not contain a reference
* //to mx.controls.DataGrid
*
* The following will not throw an error as Flash Player has reference to
* mx.controls.DataGrid
*
* import mx.controls.DataGrid;
*
* var dg:DataGrid;
*
* var ClassReference:Class = Reflection.getType("mx.controls.DataGrid");
* var dataGrid:* = new ClassReference();
* //executes without error
*
* </listing>
*
* @param The String representation of the class type
* @throws ReflectionTypeResolveException
*
*/
public static function getType(type:String) : Class
{
try {
var ClassReference:Class = getDefinitionByName(type) as Class;
}
catch (error:Error)
{
throw new TypeError( type );
}
return ClassReference;
}
}
}