IT’S GONE! (gasp)
Ok a little dramatic but here’s the thing. attachMovie doesn’t exist in AS3, and for good reason.
In Flash CS3, draw a box on the stage then convert that box to a MovieClip named Box. In the Linkage dialog (or Advanced section of the Properties dialog), set the linkage to Export for Actionscript. Notice the base class is set to flash.display.MovieClip, which is perfectly fine for this example. Click OK.
We now have a dialog box that basically tells you the class Box doesn’t exist so it will be created for you in the SWF “upon export” (basically…just click OK and move one).
This is a nice feature. What it allows you to do is now create instances of this class. So, I return to the question. Where is attachMovie?
Take the following partial code snippet. It basically loops over some dummy data, creates a new Box() instance, sets properties on it, and adds it to the “_root” child list. The boxes will be aligned one after another in a diagonal line.
var data:Object = new Object();
data.rows = 10;
data.columns = 6;
var __x:int = 0;
var __y:int = 0;
var boxTemp:Box;
for(var i:int = 0; i < data.rows; i++){
boxTemp = new Box();
boxTemp.x = __x;
boxTemp.y = __y;
addChild(boxTemp);
__y+= 20;
__x+= 20;
}
That’s it for this quick tip. I was working on some AS3 in Flash CS3 and my mind kept reverting to AS2. I wrote the entire example above with attachMovie and variables x and y (conflicts with the x and y properties of the root display object).
My mind had to revert to AS3 in the Flash IDE, which was a bit weird but no biggie.
Look for more of these quick tips. I’ll post’em whenever I get a chance.