JSFL – Automate Getters and Setters Command

Well my last JSFL attempt, as it turns out, wasn't such the bright idea I thought it might be when I sat down to build it. As Keith kindly pointed out "a template would be simpler". So hopefully this one may be a tad more useful.

I've been doing a lot more development involving a lot of class file creation lately, and while I'm getting more and more comfortable with each class I create I find there are some things that are just a pain in the ass. I have been following the OOP convention of writing implicit getters and setters in my class files. For those not familiar with what I'm talking about I would recommend picking up a copy of Object Oriented ActionScript for Flash 8. However to give a quick overview, when writing properties in your class files, instead of allowing instances of the class to directly access the properties, its recommended that you define getter methods that provide read access and setter methods that provide write access to a the property. Consider the following example:

private var __myProperty : String;// Getters and Setters
public function get _myProperty(Void) : String
{
return __myProperty;
}
public function set _myProperty(newValue : String) : Void
{
__myProperty = newValue;
}

The above example illustrates the aforementioned pain in the ass I spoke of. I understand the need for the code to be written this way and don't have a problem with the concept, but I'm lazy and hate doing things more than once if I can avoid it. Following the convention of writing implicit getters and setters now means I need to write (at minimum) 9 lines of code for every property I include in my class (not including comments or documentation).

This brought up the idea to create a command to automate this for me since in most cases my getters and setters happen to be very basic. This time though I thought I'd save some time and find out if there was a faster way to do it than a JSFL command or see if someone else had already beat me to the punch. As luck would have it, Jesse Warden had already built such a script. It allows you to create getter and setter code along with the initial property code via a simple form inside Flash. Jesse was also kind enough to provide the source code that gave me a great (almost already complete) springboard to which I could make a command to build a getters and setters command that follows the coding convention I use in my class files.

This brings us to the point of this post (yeah I'm a bit long winded), my Getters/Setters command. I took Jesses code and built upon it to end up with a JSFL extension that provides the following:

Writes the property code - allowing you to specify static/public/private attributes (default is private), data type, and initial value
Writes the Getter and Setter code (including comments)
Writes AS2DOC comments for documentation output
Outputs code to the Actions Panel as well as the output window

Nothing too fancy, and really most of the work was Jesse's. I reordered a few things for input speed and added a small amount of code to what was already a great script. Just thought I'd pass it along (with Jesse's blessing) in case anyone else may benefit from it.

Download (.mxp) | Source Code (.zip)

Now if JSFL only worked in SE|PY I'd be in really happy ;)

2 Responses to “JSFL – Automate Getters and Setters Command”

  1. jooe Says:

    your source link is broken.

  2. Crucial Says:

    @jooe thanks for the heads up. All fixed now :)

Leave a Reply


Visit Portfolio :

Crucial Limit

Client List :

Aces Tattoos | 82 Tattoo | Eric Peacock | Kustom Tattooz | Laser Imaging & Design | Laterras R. Whitfield | Solipsum | Travelocity ExperienceFinder {beta} | Travelocity | ZSI

Socialize:

Flickr | View Dave Gillem's LinkedIn profileView my LinkedIn profile | Twitter | Facebook | Become a fan of Crucial Limit on Facebook Become a fan on Facebook

Add to:

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin