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.

Advertisements

4 comments so far

  1. Matt on

    Thanks for this, very useful.

    • sambrick on

      All of these posts are done for you Matt 😉

  2. Germán on

    Very useful, thanks!

  3. emre on

    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;
    }


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: