1,ActionScript 3.0已经完全OO,所有AS代码都必须写在类里
2,AS的package和Java一样是与物理目录对应的,com.hideto.MessageManager类必须保存在com/hideto/MessageManager.as
3,属性声明
[code]
private var count:uint;
[/code]
4,implicit getters and setters
[code]
package {
public class Counter {
private var _count:uint;
public function Counter() {
_count = 0;
}
public function get count():uint {
return _count;
}
public function set count(value:uint):void {
if(value < 100) {
_count = value;
} else {
throw Error();
}
}
}
}
[/code]
这样可以直接使用counter.count,get和set让count方法变成一个public属性
5,静态方法与静态属性
[code]
public static test():void {}
private static var _example:String;
[/code]
6,继承
[code]
public class Subclass extends Superclass
[/code]
7,常量
[code]
public static const EXAMPLE:String = "example";
[/code]
8,事件分发
要想使用addEventListener()和removeEventListener(),类必须继承EventDispatcher(Sprite就继承自EventDispatcher)
2,AS的package和Java一样是与物理目录对应的,com.hideto.MessageManager类必须保存在com/hideto/MessageManager.as
3,属性声明
[code]
private var count:uint;
[/code]
4,implicit getters and setters
[code]
package {
public class Counter {
private var _count:uint;
public function Counter() {
_count = 0;
}
public function get count():uint {
return _count;
}
public function set count(value:uint):void {
if(value < 100) {
_count = value;
} else {
throw Error();
}
}
}
}
[/code]
这样可以直接使用counter.count,get和set让count方法变成一个public属性
5,静态方法与静态属性
[code]
public static test():void {}
private static var _example:String;
[/code]
6,继承
[code]
public class Subclass extends Superclass
[/code]
7,常量
[code]
public static const EXAMPLE:String = "example";
[/code]
8,事件分发
要想使用addEventListener()和removeEventListener(),类必须继承EventDispatcher(Sprite就继承自EventDispatcher)