Join Todd Perkins for an in-depth discussion in this video Using the Actions panel to format code, part of ActionScript 3.0 in Flash Professional CS5 Essential Training.
- View Offline
Whether you are cleaning up your own code or reformatting code in a file you have received from someone else, Flash makes it easy to format your code exactly how you want it. Before you have Flash automatically format your code, however, you need to make sure there are no errors. You can find out that there are no errors in your code by testing a movie. If you don't see any syntax errors in the compiler errors window, you should be okay to autoformat your code.
Code formatting is controlled through the Auto Format settings in Flash preferences. So if you go to Flash preferences or Edit > Preferences on the PC and click the Auto Format category, you can control the settings here. So let's say I unchecked all these boxes, and I get a preview of what my code will look like. Notice the curly braces, they are on the same line as the function name. I click OK, and my code looks the same as it did before, until I clicked the Auto Format button. So we click that button, which looks like an indented paragraph, Flash will format your code based on those settings.
Now personally, I like to have my curly braces on separate lines and have the settings as I had them before. So I am going to change it back, but if you prefer this way, by all means, keep your code like that. So I click OK and to get my code back to how I had it, all I have to do is click the Auto Format button again. And Flash will format the code based on my settings. Again, this works really well if you get code from someone else and you prefer to read code in a different way.
So whenever you want to reformat your code, simply check that there are no errors and then click the Auto Format button and let Flash do all the work for you.
- Understanding the building blocks of ActionScript
- Working with the display list
- Using dot syntax
- Navigating the Timeline
- Creating document classes
- Linking classes to Library objects
- Adding drag/drop functionality to objects
- Creating a slide show
- Loading and running code in an external SWF
- Working with text
- Accessing XML data
- Playing audio and video with ActionScript