Saturday, 4 June 2011

Get & Set (getter & setter) in As3.0

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

2 comments: