class test{
private var authorStr:String
public function test(){
authorStr="fanflash"
}
public function set author(dt:String){
this.authorStr=dt;
}
public function get author():String{
return this.authorStr;
}
}
在使用的時候,除了可以用正常的方式訪問如:
var t=new test();
trace(t.author);
t.author="www.fanflash.cn"
trace(t.author);
也可以使用這種方式:
t.__set__author("fanflash.cn");
trace(t.__get__author());
但是要注意的是在聲明的時候不能使用標標準的格式:
var t:test=new test();
因爲這樣的話編譯器就會去檢查類裏面有沒有這個方法,進而會報錯
本文轉自:http://www.5uflash.com/flashjiaocheng/Flashaschengxu/470.html