Variable Enumeration And Object Introspection - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

Variable enumeration and object
introspection
In Flex 1.x (ActionScript 2.0), using a
properties on an object. In Flex 2 (which uses ActionScript 3.0), only dynamically added
properties are enumerated by
enumerated in
for-in
display any properties in a
displays properties in a
To list all of the public properties and methods of a class or class instance, use the
method and to parse the results use the E4X API. The
describeType()
method is in the flash.system package. The method's only parameter is the object that you
want to introspect. You can pass any ActionScript value to it, including all available
ActionScript types such as object instances, primitive types such as uint, and class objects. The
return value of the
describeType()
description of the object's type. For more information about using E4X, see the Flex 2
Developer's Guide.
The following example introspects the Button control and prints the details to TextArea
controls:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="getDetails()">
<mx:Script><![CDATA[
import flash.system.*;
public function getDetails():void {
// Get the Button control's E4X XML object description:
var classInfo:XML = describeType(button1);
// Dump the entire E4X XML object into ta2:
ta2.text = classInfo.toString();
// List the class name:
ta1.text = "Class " + classInfo.@name.toString() + "\n";
// List the object's variables, their values, and their types:
for each (var v:XML in classInfo..variable) {
ta1.text += "Variable " + v.@name + "=" + button1[v.@name] + " (" +
v.@type + ")\n";
}
176
Migration Patterns
for-in
loops. Declared variables and methods of classes are not
for-in
loops. This means that most classes in the ActionScript API do not
loop. The generic type Object is still a dynamic object and
for-in
loop.
for-in
method is an E4X XML object that contains an XML
loop on an object let you enumerate over all
describeType()

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents