Introduction

The 2 most important classes in this library are the Type and ClassUtils classes. The Type class will give you all the information of a class while the ClassUtils class contains utility methods for working with class objects.

Using as3commons-reflect is really easy, after reading this short introduction the only thing you might need is having a look at the API to navigate through the properties and methods exposed by the library. Here below we give some short instructions on how to use the library.

Assuming you have a class called Person in the package com.company.domain) you want to use reflection on, you start by getting its “Type” in one of the following methods:

By class…

var type:Type = Type.forClass(Person);

… by instance

var person:Person = new Person();
var type:Type = Type.forInstance(person);

… or by class name…

var type:Type = Type.forName(“com.company.domain.Person”);
// or var type:Type = Type.forName(“com.company.domain::Person”);

Once you have a type instance you can get access to all variables, constants, accessors (getters/setters) and methods defined by that type and the properties of the type:

type.accessors
type.constants
type.fields
type.fullName
type.isDynamic
type.isFinal
type.isStatic
type.methods
type.name
type.staticConstants
type.staticVariables
type.variables
method:Method = type.methods[0];
retType:Type = method.getReturnType();
method.invoke(object, [arg1, arg2]);
accessor:Accessor = type.accessors[0];
metadata:Metadata = accessor.getMetadata(“myMetadata”);
arg:MetadataArgument = metadata.getArgument(“myArg”);