Using Get and Set keywords
Getter and setter methods are useful for class encapsulation. In an encapsulated class, the instance variables should not have a public access modifier. Because the public variables can be easily modified by another class without knowing a source class object. So we have to use private variables in encapsulation. If we declare private variables then no one can not access it from outside of the class
We can access this private data through both Getter and Setter methods. Using Getter and Setter is very easy in as3. Its a simple public method for accessing the private variables without calling the parenthesis ()
syntax:-
private var _instance:datatype;
public function get functionName():datatype
{
// send the private variable values
}
public function set functionName(value:datatype): void
{
// assn value into the private variables
}
get and set.rar
good work man
ReplyDeleteCan u please explain how to access the getter and setter.Thanks.
ReplyDelete