Abdulcode

Pages

Jul 23, 2010

AS3 : Dynamic classes

A dynamic class defines an object that can be altered at run time by adding or changing properties and methods. A class that is not dynamic, such as the String class, is a sealed class. You cannot add properties or methods to a sealed class at run time.

You create dynamic classes by using the dynamic attribute when you declare a class. For example, the following code creates a dynamic class named "DynamicClass".

Code : /*Main.as*/
package
{
import flash.display.Sprite;

public class Main extends Sprite
{
public function DynamicClassCode()
{
var dClass:DynamicClass = new DynamicClass();

dClass.age = 25; // Dynamically add new variable.
// Dynamically add new Method.
dClass.getDetails = function():void
{
trace(dClass.nama);
trace(dClass.age);
}

dClass.getDetails(); // Method call
}
}
}

dynamic class DynamicClass
{
public var nama:String = "Abdul";
}

No comments:

Post a Comment