All Downloads are FREE. Search and download functionalities are using the official Maven repository.

flash.utils.getDefinitionByName.as Maven / Gradle / Ivy

There is a newer version: 4.1.8
Show newest version
package flash.utils {
import joo.getQualifiedObject;

/**
 * Returns a reference to the class object of the class specified by the name parameter.
 * @param name The name of a class.
 *
 * @return Returns a reference to the class object of the class specified by the name parameter.
 *
 * @throws ReferenceError No public definition exists with the specified name.
 *
 * @example The following example uses the class GetDefinitionByNameExample to create an orange square on the stage. This is accomplished using the following steps: 
    *
  1. Variables for the background color of orange and size of 80 pixels are declared, which will later be used in drawing the square.
  2. *
  3. Within the constructor, a variable ClassReference of type Class is assigned to Sprite.
  4. *
  5. An instance of ClassReference called instance is instantiated.
  6. *
  7. Since instance is, by reference, a Sprite object, a square can be drawn and added to the display list using the methods available to Sprite.
* * package { * import flash.display.DisplayObject; * import flash.display.Sprite; * import flash.utils.getDefinitionByName; * * public class GetDefinitionByNameExample extends Sprite { * private var bgColor:uint = 0xFFCC00; * private var size:uint = 80; * * public function GetDefinitionByNameExample() { * var ClassReference:Class = getDefinitionByName("flash.display.Sprite") as Class; * var instance:Object = new ClassReference(); * instance.graphics.beginFill(bgColor); * instance.graphics.drawRect(0, 0, size, size); * instance.graphics.endFill(); * addChild(DisplayObject(instance)); * } * } * } * */ public function getDefinitionByName(name:String):Object { var clazz:* = getQualifiedObject(name.replace("::",".")); if (typeof clazz !== 'function') { throw new ReferenceError(name); } return clazz; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy