rss
twitter

Saturday, August 29, 2009

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.

Bookmark and Share

3 comments:

help with business dissertation May 7, 2013 at 4:38 AM  

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

  © Blogger templates by Ourblogtemplates.com updated with zenplate.com tips

Back to TOP