A getter is a function with a return value depending on what we return. The installer always has one parameter, since we give the variable a new value through the parameter.
First we create an instance of the class containing getter and setter, in our case it is "a". Then we call the setter, if we want to change the variable and using the point syntax, we call the setter function, and using the = operator, we fill in the parameter. To get the value for a variable, we use a getter in the same way as shown in the example (a.myVar). Unlike a regular function call, we omit the parentheses. Do not forget to add the return type, otherwise there will be an error.
package {
import flash.display.Sprite; import flash.text.TextField; public class App extends Sprite { private var tsecField:TextField; private var tField:TextField; public function App() { myTest(); } private function myTest():void { var a:Testvar = new Testvar(); tField = new TextField(); tField.autoSize = "left"; tField.background = true; tField.border = true; a.mynewVar = "This is the new var."; tField.text = "Test is: "+a.myVar; addChild(tField); } }
}
import flash.display.Sprite;
import flash.text.TextField;
the Testvar class extends Sprite {public var test: String;
public function Testvar() { } public function set mynewVar(newTest:String):void { test = newTest; } public function get myVar():String { return test; }
}
source share