AS2 → AS3: Adding Linked Symbols To The Stage
This is just a quick little tip on how to add symbols you've marked for linking in the library to the stage. There is a new way to handle adding things to the display list and this is the old way:
-
var holder_mc:MovieClip = this.createEmptyMovieClip("holder_mc", this.getNextHighestDepth());
-
var box_mc:MovieClip = holder_mc.attachMovie("box", "box1_mc", holder_mc.getNextHighestDepth(), {_x: 100, _y: 50});
Here is the AS3 equivalent of the above:
-
var holder:Sprite = new Sprite();
-
var box:Box = new Box();
-
-
box.x = 100;
-
box.y = 50;
-
-
holder.addChild(box);
-
this.addChild(holder);
Notice in the exampe files that I've linked the box to a class to a class called Box and a base class of flash.display.MovieClip (the default when you check export for AS). Even though I never created a Box class, Flash thinks that there isn't one and creates one automatically for me (with no code in it of course). This is the new way to apply "linkage IDs" to exported clips in AS3. You can go ahead and create a Box class if you'd like but there is no need for it because we aren't adding any functionality to this particular case, just need to get it out onto the stage through code.
It is kind of nice being able to set up a sprite or movie clip and initialize everything before adding it to the stage.
If you found this post useful, please consider leaving a comment, subscribing to the feed, or making a small donation.
3 Comments
Hey Matt,
I really like the whole "AS2 → AS3" series. I think its a great way for comparative purposes for people to learn and think its a nice approach for the blog. Thanks for doing this, been meaning to thank you for a while since I saw these.
Perhaps the only suggestion would be to have the AS2 examples saved back to Flash 8, but thats up to you and only a suggestion.
Again I think this approach "AS2 → AS3" is a great resource to the community and will offer those adapting AS3 a good comparative method for learning from AS2.
Still hoping there might be some more AS2 nugguts your gonna release also
Keep up the great work, I really like the new EVOLVE blog, great job!
Hey WT,
Thanks for the kind words.
As for the AS2 Flash 8 files. I figured that anyone who is going to be converting to AS3 would have CS3 installed so the backwards compatibility of the files wouldn't be necessary.
If you need any of the files on here saved back for Flash 8, just let me know and I'll happily do so.
Thanks!













That is so nice!
I love how clean AS3 is and I love how I don't have to worry about adding in getNextHighestDepth();