和很多变成语言一样,类的属性通过get和set来实现,但是在AS三种有特殊的写法:public function get methodName():String 或者 public function set methodName(name:String):void
package
{
public class PropertyDemo
{
var name:String = "Vince";
public function PropertyDemo()
{
}
public function get getName():String
{
return this.name;
}
public function set setName(name:String):void
{
this.name = name;
return;
}
}
}
{
public class PropertyDemo
{
var name:String = "Vince";
public function PropertyDemo()
{
}
public function get getName():String
{
return this.name;
}
public function set setName(name:String):void
{
this.name = name;
return;
}
}
}