Avoiding the Compiler’s Whip: 9 Flash AS3 Tips for Beginners
These tips are based on Flash CS4. They are also useful for CS3 and possibly some earlier versions.
It’s been about 3 weeks since I started programming in Flash AS3. I’ve caused the compiler an unholy amount of errors and here’s what I’ve learned.
The List
- FlashDevelop
- Preventing Memory Leaks
- Event Listeners
- Display List
- Global Variables
- Box2D Physics Engine
- mathMisc.as
- MonterDebugger
- Setting the Class of a .swf
- Setting the Path to your AS3 files
This editor is leagues better than the one included in Flash CS4. Autocomplete and function parameters are two of its greatest features.
It’s extremely important to a big project that you understand how to make the garbage collector delete objects. I highly recommend reading this link on AS3 Garbage Collection, or you may spend several hours reworking your Flash Project when you find out it has memory leaks.
Adding Event Listeners to objects should usually be invoked with addEventListener( Event, callback, false, 0, true ). If you do not have the last parameter set to true, the garbage collector will not delete that Event Listener’s class until you manually remove it.
Objects most recently added to the stage with addChild() will appear on top of other objects. When you invoke addChild(displayObject), it is stored in the parent object’s display list. Flash goes through each display list, starting with the stage, and renders each object.
From an Object Oriented perspective, these are bad. However, sometimes it’s really useful to have them.
One of the top physics engines for Flash, and for good reason. It is fast, powerful, and has numerous ports to other languages. One word of caution: you cannot use concave shapes.
These are just a few useful math functions I didn’t find in Flash. The naming and arguments follow the similar functions from Game Maker 7. If you’re good at trig these are very simple, but still useful. (point_direction, point_distance, lengthdir_x, lengthdir_y, degToRad, radToDeg)
Along with providing an nice graph of your Flash’s memory usage and FPS, MonsterDebugger will allow you to trace around your classes and see everything going on under the hood. This helps when you start getting runtime errors, but note that it takes a while to figure out the structure of this debugger to get useful data from it.
You can specify a default ActionScript class that a .swf file should load on runtime. You can reach this under the Document Properties panel, where you type in the name of the file under Class (without the .as).
Flash will throw an error if it can’t find your AS3 files. You can tell Flash where to find these under File -> Publish Settings -> ActionScript 3.0 -> Sourcepaths.
Hope this helps you out a bit.
Related posts:


Leave a Reply