---
title: "FLEX提高篇--------as3reflect反射组件"
author: "hacker47"
date: "2009-04-25T14:43:22Z"
tags: []
slug: "flex-as3reflect"
draft: false
lastmod: "2009-04-25T14:43:22Z"
id: 374465
url: "https://hacker47.iteye.com/blog/374465"
---

原文件来自:[http://code.google.com/p/as3reflect/](http://code.google.com/p/as3reflect/ "点击进入")

 

AS3reflect 是一个用AS3写的反射API并且能够被用于FLASH/FLEX/AIR和AS项目中,为了使用AS3reflect在你的工程中,先下截AS3reflect.SWC 库并且引入到你的actionscript CLASS PATH

有两个最重要的类在你的库中分别是Type和ClassUtils类,能过Type类你可以知道另一个类或者其实例的所有信息,当ClassUtils类包含这个类对象时

 举一个例子:  
假设你有一个类叫Preson在你的包com.company.domain中,你可以有下列方式操作它们,获取你想要的信息:

```
By class...

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

... or 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");
```

 

一旦你有一个type实例,你可以访问所有变量,常量,操作,setter/getter存取器,并且可以得到方法定义的类型以及属性的类型如下:

 

 

```
type.accessors

type.constants

type.fields

type.fullName

type.isDynamic

type.isFinal

type.isStatic

type.methods

type.name

type.staticConstants

type.staticVariables

type.variables
```