- Create a class called MyClass, and declare the following three variables (pay attention to the underscore in 2 and 3 :
- Set myVar1 to public, and _myVar2 and _myVar3 to private.
- Save the class under the name "MyClass.as".
- Create a Flash document and make an object called testClass of the type MyClass.
- Save the document in the same folder as the class file.
- In the Flash document, set the value of myVar1 to 100.
- Trace it to the output panel.
- Try to set the value of _myVar2 or _myVar3 to see the private modifier in effect.
- Open MyClass.as and create a function called getVar2() and setVar2().
- Make them either set the value of _myVar2 or return the value of _myVar2
- Open the flash document and use setVar2() to set the value to 200
- Use getVar2() to trace the value of the private property.
- Create a getter/setter for _myVar3 called myVar3.
- Set the value of _myVar3 via it's setter to 300, and use the getter to trace it to the output panel.
Basics of object-oriented programming
Classes > Variables
Get and Set accessor methods