Similar to other programming languages like C# there is possibility to create setters and getters in ActionScript. Here is an example:
//method accesed privately
private var _title:String = "Title";
//getter
public function get title():String
{
return m_title;
}
//setter
public function set title(aTitle:String):void
{
_title = aTitle;
/*
* here can be other code that you need to be executed
* when somebody sets your variable
* example:
* this.dispatchEvent(new Event('ModelTitleChangeEvent'));
*/
}
Use it or not? It depends on You and Your project. If project is advanced it is useful solution. And in my opinion code is easy to understand.
//method accesed privately
private var _title:String = "Title";
//getter
public function get title():String
{
return m_title;
}
//setter
public function set title(aTitle:String):void
{
_title = aTitle;
/*
* here can be other code that you need to be executed
* when somebody sets your variable
* example:
* this.dispatchEvent(new Event('ModelTitleChangeEvent'));
*/
}
Use it or not? It depends on You and Your project. If project is advanced it is useful solution. And in my opinion code is easy to understand.
No comments:
Post a Comment