ActionScript 3 For Noobs
I originally learned some basic ActionScript simply because I wanted to present my photos in a clean, easy-to-use interface on the web, and I didn't want to buy (or pinch) someone else's application to do it. After falling into just about every beginner's pitfall you could possibly find, I started keeping notes on things that now seem obvious, but at the time really had me stumped. I present them here for your general edification, amusement and awe at how little I knew. Hopefully they'll help some other novice programmers when they're scratching their heads over the same things I was....
#1Manipulating Height and Width of displayObjects
You declare and instantiate a displayObject in ActionScript (such as a MovieClip or Sprite) and then adjust its width and height properties. You check the properties with a trace statement, but they are still set at 0, despite the fact that you've adjusted them.
Some background information before explaining why this is so, may facilitate your understanding... displayObjects such as MovieClips and Sprites all share the base class of displayObjectContainer. This base class includes all objects that are essentially containers in Flash (that is, they hold (or "contain") other objects. So, when you create a new MovieClip or Sprite, you are creating an empty container. Until you put something in that container, using the addChild method, there are essentially no width or height properties to adjust, as the empty container's width and height are both equal to zero.
The solution? First, add a child to the displayObject in question (for example):
mySprite.addChild(myGraphic)
...and then adjust the height and width properties.
#2Beware the Bandwidth Profiler!
This is a good one... I haven't tested this in Flash CS5, but it was definitely a problem with both CS3 and CS4.
When you are working out where to place items on the stage (their Y position in particular), you may well be calculating the height of the stage to do this, and placing your objects in relation to other objects on the stage, or in relation to the stage itself. After making your calculations you go and test your Flash application, with the Bandwidth Profiler turned on. Your stage elements are out of alignment along the vertical axis.
This is a bug in CS3 and CS4 that adds the dimensions of the Bandwidth Profiler to the height of the stage, throwing out all the careful calculations you have made by about 80 pixels (or something like that). How rude!
The solution? Turn off the Bandwidth Profiler and test your movie again. ...ah, what a relief!!