FDT 4 – How to auto-generate Getters and Setters
Again, this is common knowledge but I thought I would post it for convenience and the hope that it will help someone else out in the future.
To generate a getter and/or a setter create a variable in the declaration section of your class. Make sure to prefix it with an underscore _ and also make it private. Simply put the cursor in the variable and press Cmd-1 (on a Mac). FDT will then generate the statements for you. For instance, in the below statement, if I put the cursor on the _alertText_str variable here:-
private var _alertText_str:String;
And press Cmd-1, FDT will generate:-
public function get alertText_str() : String {
return _alertText_str;
}
public function set alertText_str(alertText_str : String) : void {
_alertText_str = alertText_str;
}
Thanks to @dougal07 for showing me this.
Thanks for this, very useful.
All of these posts are done for you Matt
Very useful, thanks!
What if I follow pascal syntax and considering my public methods start with an Uppercase letter of the private members’ first letter?
Could it be done automatically with a twist in the template?
Say;
private var myVal : String;
public set MyVal (value : String) : void
{
this.myVal = value;
}
public get MyVal () : String
{
return this.myVal;
}