Posts Tagged ‘ActionScript 3’

|

Auto-generate getter / setter of ActionScript 3 in TextMate

Sunday, January 31st, 2010

Using get set accessor to access instance variable is a good practice in object oriented programming. Many OOP languar supports accessor shortcuts. For example, Objective-C supports using @property tag instead of writing two individual get / set pair functions. However, There is no such shortcuts in ActionScript that we have to explicitly write the two get set functions even They are the template one. This can be a time consuming process.

Recently Flex Builder supports automatically generate those getter setter at the end of the class definition. I am doubting if there are such snippets for TextMate.

After searching on Internet. I do found one for AS2. It is a ruby script for TextMate that prompt a list of the instance variables and you can choose one and it generate the get set accessor of that variable.

That’s the half way of my goal. Therefore, I modify the code and make it AS3. I also make two version of the snippets. One version follows the original concept that prompt a list to let user choose one instance variable. The other will generate accessors for all instance variables immediately.

Please follow the steps in the help file to install the snippets into your TextMate.

Results:

Setup:

Please follow this help file to install the snippets into TextMate:

At last, thanks nesium.com for the as2 version of accessors generation and thanks Simon Gregory for the actionscript 3 TextMate bundles.

FAQ

Q: Error about unit type conversion occurs when running.

A: This occurs in the original AS2 version script because the osascript tried to run in 64-bit mode in Snow Leopard but failed. I fix it by adding “arch -i386″ when calling the osascript to run in 32-bit mode. The script you download should have this fix and this is for your reference if you face this problem sometimes.

Here is a tech note about this issue from Adobe Support: http://kb2.adobe.com/cps/516/cpsid_51615.html

Tags: , ,
Posted in Flash | 2 Comments »

|
design by makzan. powered by wordpress.