Home Tutorial Flex Flex-components Dynamic class in Flex 3

 
 

Share on Google+Share on Google+
Dynamic class in Flex 3
Posted on: July 14, 2010 at 12:00 AM
Advertisement
In flex, you must have created ActionScript classes where properties and methods are declared and defined

Dynamic Class In Flex

In flex, you must have created ActionScript classes where properties and methods are declared and defined. Flex also let you add properties and methods at run time when you create an object of the class. This all can be achieved using "dynamic" keyword while creating class.

DynamicClass.as

package {

public dynamic class DynamicClass {

public var name:String;

public function displayName():String {

return name;

}

}

}

The above class only has one property "name" and one method "displayName()". The above class has the capability to be set new properties and added functions at run time. For example: In the below mxml, we added new property "place" and one new method "displayPlace()".

Dynamic.mxml

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

creationComplete="init()">

<mx:Script>

<![CDATA[

import mx.controls.Alert;

public function init():void {

var dynamicClassObj:DynamicClass = new DynamicClass();

dynamicClassObj.name = "Roseindia";

// Adding property to the object of dynamic class at runtime

dynamicClassObj.place = "New Delhi";

// Adding method to the object of dynamic class at runtime

dynamicClassObj.displayPlace = function():String {

return this.place;

};

Alert.show(dynamicClassObj.displayName()+", "+ dynamicClassObj.displayPlace());

}

]]>

</mx:Script>

</mx:Application>

The output of the above application is as below:

Advertisement

Related Tags for Dynamic class in Flex 3:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 14, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com