Tag Archives: Setter

Learning Class Programming on Flash – Setter and Getter

In this section we will discuss about how to set value into a class and get the value from it. After we learned about Accessibility of Class, we know that we can’t directly access attributes and methods from some class if it set as private. To solved this problem we need public method for set value and get value from the class, and its called setter and getter. For a sample here is two variable that we want to set and get the value.

Setter Method :

This is public function for send one or more values into class and update the private atributes. Sample of this code such as object.setMoveSpeed(value), object.setBackgroundImage(value, value), and object.setOnClickListener(value). This image below is a sample code for setter method.

And if you also want to send parameter, you can use ‘changeColor(param:String)’ and then use ‘color = param;’ to set the color value.

Getter Method :

This is public function for get private variables value from some class. Sample for this code like object.getPosition(), object.getChildNum(), and object.getIndex(value). This image below is a sample code for getter method.

You can send parameter with this method too and depend on what the parameter is use for.

Next Step – Event Listener

Tagged , , , , , , , , , , , ,