我使用flash builder getters和setters方法在动作脚本中创建了一个bean类。 这个班是:`
package default{
public class AccountBean
{
private var _username:String;
private var _email:String;
public function get username():String {
return _username;
}
public function set username(value:String):void {
_username = value;
}
public function get email():String {
return _email;
}
public function set email(value:String):void {
_email = value;
}
public function AccountBean() {
}
}
}
如何使用set和get方法,这个类的创建是否正确?请帮忙
答案 0 :(得分:1)
是的,这是对的!
var bean:AccountBean = new AccountBean();
//using the setters
bean.username = "Whatever";
bean.email = "bean@whatever.com";
//using the getters
trace( bean.username , bean.email ); // Whatever bean@whatever.com