简体   繁体   中英

How to create a bean in ActionScript?

I have created a bean class in action script using flash builder getters and setters method. the class is :`

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() {
    }
}
}

How to use set and get methods for this, is this creation of class is correct or not? please help

Yes, it's correct!

     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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM