In flex, you must have created ActionScript classes where properties and methods are declared and defined
In flex, you must have created ActionScript classes where properties and methods are declared and definedDynamic 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: