ActionScript Formatter

Paste an AS3 package or a legacy AS2 script and get consistent indentation for every class, function and event handler.

ActionScript
Formatted ActionScript
Runs locally in your browser

About the ActionScript Formatter

ActionScript kept the curly brace grammar of ECMAScript but added package blocks, typed declarations such as var frames:int and metadata tags like [Embed]. This formatter walks the source as a stream of tokens, so a colon that belongs to a type annotation is never confused with the colon of a ternary expression, and a brace inside a string literal is never counted as a block.

The re-indenter changes whitespace and nothing else. Identifiers, numeric literals, string contents and comment text come out byte for byte identical, which matters when a Flex project mixes E4X literals and inline XML into the source. Turn Split statements onto new lines off if you want to keep the line breaks you already have and only fix the leading indentation.

Nested package and class blocks are the usual reason AS3 files drift out of shape after a merge. Feed the whole file in and every level is rebuilt from the brace depth, with else and catch kept on the same line as the closing brace they follow.

Because ActionScript syntax overlaps heavily with JavaScript, code that is really plain ECMAScript will get a better result from the JavaScript Beautifier, which runs a full parser and can also normalise operator spacing.

How to use

  1. Paste your .as file into the left pane or press Sample to load a small AS3 class.
  2. Pick an Indent width. Flex projects normally use 4 spaces, older Flash libraries often use tabs.
  3. Leave Split statements onto new lines on for compressed source, or switch it off to preserve your existing line breaks.
  4. Use Copy for the clipboard or Download to save the result as an .as file.

Common questions

Does it work with ActionScript 2 as well as AS3?
Yes. Both dialects use the same brace and comment syntax, so the indentation pass handles AS2 timeline code and AS3 class files alike.
Will metadata tags such as [Bindable] be moved?
They stay on their own line at the indentation of the declaration that follows them. The text inside the brackets is never rewritten.
Are inline E4X XML literals safe?
The tokenizer treats quoted regions as opaque, so attribute values survive. Bare XML written across several lines without quotes may pick up the surrounding indentation, so check the result before saving.
Does it add spaces around operators?
No. Spacing between operators is left exactly as you wrote it because rewriting it would require a full expression parser and risks changing meaning in edge cases such as a++ +b.