the blog
Back to -Blog

ActionScript Code Formatting In Amethyst

How to auto-format code the way you like it...
by Huw Collingbourne
Friday 12 December 2008.

Amethyst SapphireSteel Software’s Adobe Flex development environment - has a built in ActionScript code formatter. Here is a short introduction to some of its features.

Code formatting can be a very personal thing. If you are used to having opening curly brackets on new lines and spaces around binary operators such as &&, || and +, you may feel like tearing your hair out when you see code that adopts a different set of conventions (or, worse still, none at all!). Amethyst PE’s auto-code formatting can save your hair by automatically reformatting ActionScript code to adopt your preferred style.

Let’s look at an example. We’ll imagine that the code below was written by a junior programmer (we’ll call him Gussie Fink-Nottle) who’s just joined the company. In spite of being informed of our preferred code formatting options, Gussie has nevertheless dashed off several thousand lines of code that break all our style rules. Here is a typical example...

Gussie’s code just as he wrote it...

Now, while we could force him to rewrite his code by adding spaces, inserting newlines and indenting in accordance with the company’s standards, that would take him many hours which would be better spend doing other things. Fortunately, with Amethyst PE, we can reformat his code almost instantly. Just select Edit, Advanced, Format Document or press the associated shortcut keys (the default is CTRL+E, D) and the above mess of code is immediately reformatted into this...

Here the code is formatted according to the company’s preferred style...

While this happens to be our company’s preferred coding style it is quite possible that your company prefers something different. For example, maybe your company insists on spaces between each function name and the opening parenthesis, no spaces around binary operators such as + and ||, opening curly brackets placed on new lines and indented case labels). No problem. All you have to do is set a few options and then instantly reformat the document to produce this...

Auto-formatting options are all set up in the Formatting Options dialog (Tools, Options, Text Editor, ActionScript, Formatting):

This has four pages of options. In order to format Gussie Fink-Nottle’s code according to my company’s preferred style, these are the options which I selected:

No matter whether you want to ensure that your own code is consistently formatted or whether you have a pesky junior programmer like Gussie Fink-Nottle, setting up the options here and then pressing CTRL-E, D (or another shortcut if you have an alternative keyboard layout in your Visual Studio setup), will save you hours of re-editing and formatting work.

Bear in mind that the screenshots above show the first beta of Amethyst PE, released in December 2008. Additional options may added in future release of Amethyst PE and Professional Editions so be sure to check the SapphireSteel Software web site for the latest information.

- The code formatting options are explained in more detail in this article.


- Download Amethyst
- A Brief Guide To Amethyst

Bookmark and Share   Keywords:  Amethyst
© SapphireSteel Software 2014