The flash.utils package provides several reflection methods that allow developers to inspect class information at runtime. These utilities can transform string class paths into actual class references and retrieve metadata about object hierarchies.
getDefinitionByName
This function converts a fully-qualified class name string into an actual class reference. When you have the class path but no direct access to the class constructor, getDefinitionByName bridges that gap.
var ClassRef:Class = getDefinitionByName("flash.display.Sprite") as Class;
var instance:* = new ClassRef();
trace(instance is Sprite);
// Output: true
The returned value is a Class object, which can be instentiated or compared against other types. This proves particularly useful when working with dynamic class loading or configuration-driven instantiation.
getQualifiedClassName
When you need to retrieve the full qualified name of an object or class, this method delivers the complete package and class path in dot notation.
var instance:Sprite = new Sprite();
trace(getQualifiedClassName(instance));
// Output: flash.display::Sprite
trace(getQualifiedClassName(Sprite));
// Output: flash.display::Sprite
Note the :: separator indicates the package boundary in the output. This method accepts both instances and Class objects directly.
getQualifiedSuperclassName
This method retrieves the parent class name for any given object or class reference. When working with inherited class hierarchies where the base class might be inaccessible, this function provides a way to discover the lineage.
var child:Sprite = new Sprite();
trace(getQualifiedSuperclassName(child));
// Output: flash.display::DisplayObjectContainer
trace(getQualifiedSuperclassName(Sprite));
// Output: flash.display::DisplayObjectContainer
Traversal Example
Combining these methods enables walking up the entire inheritance chain. Starting from a class and repeatedly querying its parent produces a complete ancestry map:
var current:Class = Sprite;
while (current != Object) {
trace(getQualifiedClassName(current));
var parentName:String = getQualifiedSuperclassName(current);
current = getDefinitionByName(parentName) as Class;
}
/* Output:
* flash.display::Sprite
* flash.display::DisplayObjectContainer
* flash.display::InteractiveObject
* flash.display::DisplayObject
* flash.events::EventDispatcher
* Object
*/
This pattern reveals the complete inheritance hierarchy, showing every encestor class from the starting point up to Object. The technique works regardless of whether you begin with a class constructor or an instantiated object.
Practical Applications
While these reflection utilities see frequent use in testing frameworks and serialization systems, understanding them clarifies how AS3 handles runtime type inspection. They prove especially valuable when building systems that must handle unknown types dynamically or when debugging complex inheritance structures.