[dynamic] classExample:className[ extendssuperClass][ implementsinterfaceName[,interfaceName... ] ] { // class definition }
class B extends class A
{
function B() // constructor
{
// super(); // Not necessary, inserted if omitted
}
function m():Number { return 25; }
function o(s:String):Void { trace(s); }
}
Scripts must be stored externally
with a single class defined in each file,
which must have the same name as the class.
importclassName : The fully qualified name of a class you have defined in an external class file.classNameimportpackageName.*
packageName : A directory in which you have stored related class files. As in Java import lets you access classes without specifying their fully qualified names.
Flash searches for class and interface definitions in the directories listed in classpath.
myClass implements interface01 [, interface02, ...]Example:
// filename Ia.as
interface Ia
{
function k():Number; // method declaration only
function n(x:Number):Number; // without implementation
}
// filename B.as
class B implements Ia
{
function k():Number { return 25; }
function n(x:Number):Number { return x+5; }
}
class someClassName
{
public var name;
public function name() { }
private var name;
private function name() { }
static var name;
static function name() { }
}
static
class members
are assigned to the class itself, not to any instance of the class.
var square_root:Number = Math.sqrt(4);
dynamic class className [ extends superClass ]
[ implements interfaceName [, interfaceName... ] ]
{
// class definition
}
dynamic
specifies that objects based on the specified class can
add and access
dynamic properties at runtime.
This behavior is common in AS, for example, calling MovieClip.createTextField() adds properties to a movie clip object dynamically.
Example
class Person
{
var name:String;
var age:Number;
}
var a_person:Person = new Person();
a_person.hairColor = "blue"; // compiler error
Using dynamic
lets you add and access properties and methods
that are not defined in the original class:
dynamic class Person
{
var name:String;
var age:Number;
}
var a_person:Person = new Person();
a_person.hairColor = "blue"; // works for dynamic class
Subclasses of dynamic classes are also dynamic.
Classes typically define "get" methods that provide read access and "set" methods that provide write access to a given property.
Implicit get/set methods are a syntactic shorthand for these methods.