| Package | system |
| Class | public class Reflection |
| Inheritance | Reflection Object |
Example :
import system.Arrays ;
import system.data.Map ;
import system.data.maps.HashMap ;
import system.reflection.ClassInfo ;
import system.Reflection ;
import system.Serializable ;
trace( "# Object isDynamic() : " + Reflection.getClassInfo(Object).isDynamic() ) ; // # Object isDynamic() : true
trace( "# String isFinal() : " + Reflection.getClassInfo(String).isFinal() ) ; // # String isFinal() : true
trace( "# Math isStatic() : " + Reflection.getClassInfo(Math).isStatic() ) ; // # Math isStatic() : true
trace("---------") ;
var map:HashMap = new HashMap() ;
var classInfo:ClassInfo ;
classInfo = Reflection.getClassInfo( map ) ;
trace( "# isInstance() : " + classInfo.isInstance() ) ; // # isInstance() : true
trace( "# isDynamic() : " + classInfo.isDynamic() ) ; // # isDynamic() : false
trace( "# isFinal() : " + classInfo.isFinal() ) ; // # isFinal() : false
trace( "# isStatic() : " + classInfo.isStatic() ) ; // # isStatic() : false
trace( "# hasInterface( Map , Serializable ) : " + classInfo.hasInterface( Map , Serializable ) ) ; // # hasInterface( Map , Serializable ) : true
trace( "# inheritFrom( Object ) : " + classInfo.inheritFrom( Object ) ) ; // # inheritFrom( Object ) : true
trace("---------") ;
classInfo = Reflection.getClassInfo(Reflection) ;
trace( "# Reflection isStatic() : " + classInfo.isStatic() ) ; // # Reflexion isStatic() : true
trace( "---" ) ;
trace( "# hasClassByName('system.data.maps.HashMap') : " + Reflection.hasClassByName("system.data.maps.HashMap") ) ; // hasClassByName('system.data.maps.HashMap') : true
trace( "# getClassByName('system.data.maps.HashMap') : " + Reflection.getClassByName("system.data.maps.HashMap") ) ; // getClassByName('system.data.maps.HashMap') : [class HashMap]
trace( "# getDefinitionByName('system.data.maps.HashMap') : " + Reflection.getDefinitionByName("system.data.maps.HashMap") ) ; // getDefinitionByName('system.data.maps.HashMap') : [class HashMap]
trace( "---" ) ;
trace( "# getClassName(map) : " + Reflection.getClassName(map) ) ; // getClassName(map) : HashMap
trace( "# getClassName(map,true) : " + Reflection.getClassName(map, true) ) ; // getClassName(map,true) : system.data.maps::HashMap
trace( "# getClassPackage(map) : " + Reflection.getClassPackage(map) ) ; // getClassPackage(map) : system.data.maps
trace( "# getClassPath(map) : " + Reflection.getClassPath(map) ) ; // getClassPath(map) : system.data.maps.HashMap
trace( "# getClassMethods(map) : " + Reflection.getClassMethods(map) ) ; // getClassMethods(map) : put,clone,remove,keyIterator,containsKey,toSource,size,toString,putAll,getKeys,get,clear,iterator,containsValue,getValues,isEmpty
trace( "# getClassMethods(map,true) : " + Reflection.getClassMethods(map,true) ) ; // getClassMethods(map,true) : put,clone,remove,keyIterator,containsKey,toSource,size,toString,putAll,getKeys,get,clear,iterator,containsValue,getValues,isEmpty
trace( "# getMethodByName(map,'put') : " + Reflection.getMethodByName(map,"put") ) ; // getMethodByName(map, 'put') : function Function() {}
trace( "# getMethodByName(map,'test') : " + Reflection.getMethodByName(map,"test") ) ; // getMethodByName(map, 'test') : null
trace( "# getSuperClassName(core) : " + Reflection.getSuperClassName(map) ) ; // getSuperClassName(map) : Object
trace( "# getSuperClassPackage(core) : " + Reflection.getSuperClassPackage(map) ) ; // getSuperClassPackage(map) : null
trace( "# getSuperClassPath(core) : " + Reflection.getSuperClassPath(map) ) ; // getSuperClassPath(map) : Object
trace("---------") ;
Array.prototype.toString = function():String
{
return "[" + this.join(",") + "]" ;
}
var ar:Array
// test with no argument
ar = Reflection.invokeClass( Array ) ;
trace( ar ) ;
//output: []
// test with 0 argument
ar = Reflection.invokeClass( Array , [] ) ;
trace( ar ) ;
//output: []
// test with 2 arguments
ar = Reflection.invokeClass( Array , Arrays.initialize(2,0) ) ;
trace( ar ) ;
//output: [0,0]
// test with 32 arguments
ar = Reflection.invokeClass( Array , Arrays.initialize(32,0) ) ;
trace( ar ) ;
//output: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
// test with 33 arguments
try
{
ar = Reflection.invokeClass( Array , Arrays.initialize(33,0) ) ;
trace( ar ) ;
}
catch( e:Error )
{
trace(e) ; // ArgumentError: Reflection.invokeClass() method failed : arguments limit exceeded, you can pass a maximum of 32 arguments.
}
| Method | Defined By | ||
|---|---|---|---|
getClassByName(name:String):Class [static]
Returns the class reference from a string class name. | Reflection | ||
getClassInfo(o:*, ... filters):ClassInfo [static]
Returns the ClassInfo object of the specified object. | Reflection | ||
getClassMethods(o:*, inherited:Boolean = false):Array [static]
Returns an array of public methods defined in the class of an object. | Reflection | ||
getClassName(o:*, path:Boolean = false):String [static]
Returns the class name as string of an object. | Reflection | ||
getClassPackage(o:*):String [static]
Returns the package string representation of the specified instance passed in arguments. | Reflection | ||
getClassPath(o:*):String [static]
Returns the full path string representation of the specified instance passed in arguments (package + name). | Reflection | ||
getDefinitionByName(name:String):Object [static]
Returns the instance of a public definition in the current Domain. | Reflection | ||
getMethodByName(o:*, name:String):Function [static]
Returns the method reference of the specified object with the passed-in property name. | Reflection | ||
getSuperClassName(o:*):String [static]
Returns the super class name as string of an object. | Reflection | ||
getSuperClassPackage(o:*):String [static]
Returns the super class package string representation of the specified instance passed in arguments. | Reflection | ||
getSuperClassPath(o:*):String [static]
Returns the super class path string representation of the specified instance passed in arguments. | Reflection | ||
getTypeInfo(o:*):TypeInfo [static]
Returns the TypeInfo object of the specified object. | Reflection | ||
hasClassByName(name:String):Boolean [static]
Returns a boolean telling if the class exists from a string name. | Reflection | ||
invokeClass(c:Class, args:Array = null):* [static]
Wrapping method which select which build method use according to the argument count (32 max). | Reflection | ||
| getClassByName | () | method |
public static function getClassByName(name:String):ClassReturns the class reference from a string class name. The string name notation can be either "flash.system::Capabilities" or "flash.system.Capabilities" but you have to provide the full qualified path of the class "Capabilities" alone will not work.
Parameters
name:String |
Class — the class reference from a string class name.
|
| getClassInfo | () | method |
public static function getClassInfo(o:*, ... filters):ClassInfoReturns the ClassInfo object of the specified object.
Parameters
o:* | |
... filters |
ClassInfo — the ClassInfo object of the specified object.
|
| getClassMethods | () | method |
public static function getClassMethods(o:*, inherited:Boolean = false):ArrayReturns an array of public methods defined in the class of an object.
Parameters
o:* | |
inherited:Boolean (default = false) |
Array — an array of public methods defined in the class of an object.
|
| getClassName | () | method |
public static function getClassName(o:*, path:Boolean = false):StringReturns the class name as string of an object.
Parameters
o:* | |
path:Boolean (default = false) |
String — the class name as string of an object.
|
| getClassPackage | () | method |
public static function getClassPackage(o:*):StringReturns the package string representation of the specified instance passed in arguments.
Parameters
o:* — the reference of the object to apply reflexion.
|
String — the package string representation of the specified instance passed in arguments.
|
| getClassPath | () | method |
public static function getClassPath(o:*):StringReturns the full path string representation of the specified instance passed in arguments (package + name).
Parameters
o:* — the reference of the object to apply reflexion.
|
String — the full path string representation of the specified instance passed in arguments (package + name).
|
| getDefinitionByName | () | method |
public static function getDefinitionByName(name:String):ObjectReturns the instance of a public definition in the current Domain. The definition can be a class, namespace, function or object.
Parameters
name:String |
Object — the instance of a public definition in the current Domain.
|
| getMethodByName | () | method |
public static function getMethodByName(o:*, name:String):FunctionReturns the method reference of the specified object with the passed-in property name.
Parameters
o:* | |
name:String |
Function — the method reference of the specified object with the passed-in property name.
|
| getSuperClassName | () | method |
public static function getSuperClassName(o:*):StringReturns the super class name as string of an object.
Parameters
o:* |
String — the super class name as string of an object.
|
| getSuperClassPackage | () | method |
public static function getSuperClassPackage(o:*):StringReturns the super class package string representation of the specified instance passed in arguments.
Parameters
o:* — the reference of the object to apply reflexion.
|
String — the super class package string representation of the specified instance passed in arguments.
|
| getSuperClassPath | () | method |
public static function getSuperClassPath(o:*):StringReturns the super class path string representation of the specified instance passed in arguments.
Parameters
o:* — the reference of the object to apply reflexion.
|
String — the super class path string representation of the specified instance passed in arguments.
|
| getTypeInfo | () | method |
public static function getTypeInfo(o:*):TypeInfoReturns the TypeInfo object of the specified object.
Parameters
o:* |
TypeInfo — the TypeInfo object of the specified object.
|
| hasClassByName | () | method |
public static function hasClassByName(name:String):BooleanReturns a boolean telling if the class exists from a string name.
Parameters
name:String |
Boolean — a boolean telling if the class exists from a string name.
|
| invokeClass | () | method |
public static function invokeClass(c:Class, args:Array = null):*Wrapping method which select which build method use according to the argument count (32 max).
Example :
import system.Arrays ;
import system.Reflection ;
Array.prototype.toString = function():String
{
return "[" + this.join(",") + "]" ;
}
var ar:Array
// test with no argument
ar = Reflection.invokeClass( Array ) ;
trace( ar ) ;
//output: []
// test with 0 argument
ar = Reflection.invokeClass( Array , [] ) ;
trace( ar ) ;
//output: []
// test with 2 arguments
ar = Reflection.invokeClass( Array , Arrays.initialize(2,0) ) ;
trace( ar ) ;
//output: [0,0]
// test with 32 arguments
ar = Reflection.invokeClass( Array , Arrays.initialize(32,0) ) ;
trace( ar ) ;
//output: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
// test with 33 arguments
ar = Reflection.invokeClass( Array , Arrays.initialize(33,0) ) ;
trace( ar ) ;
//output:
// ArgumentError: Reflection.invokeClass() method failed : arguments limit exceeded, you can pass a maximum of 32 arguments.
Parameters
c:Class — The Class of the instance to build.
| |
args:Array (default = null) — The array of all arguments to passed-in the constructor of the specified class.
|
* |