Creating Flex Component Object when knowing only Class Name of the component
If you need to get a reference to a class in ActionScript 3, but you know only the class name,
then in that case you can use the "getDefinitionByName("class name string")" to create an instance of the class.
getDefinitionByName method is available in flash.utils package
This can be easily understandble by the simple example,
import flash.utils.getDefinitionByName; var ClassReference:Class = getDefinitionByName("flash.display.MovieClip") as Class;
This creates an instance of the MovieClip class.getDefinitionByName method takes the entire class path,
so if you wanted to create an instance of MovieClip, you would provide the entire path:
var ClassReference:Class = getDefinitionByName("flash.display.MovieClip") as Class;
The following example shows how you can create a new Flex component instance by using
its class name by calling the getDefintionByName() method.
For creating Button component,
var cls:Class = getDefinitionByName("mx.controls.Button") as Class;
This will create instance to Flex Button Component,This is the same to
Button but_oj=new Button();
By using full class path with getDefinitionByName() method we can create instance to any class.
3 comments:
Dont work with AreaChart
Dont work with AreaChart
It was very informative and I also digg the way you write! Keep it up and I’ll be back to read more in the future.
Post a Comment