AS3 attachMovie() from Library

AS2 fans, you will no longer be using attachMovie() to attach items from the library to the stage.  ActionScript 3 removed the attachMovie() function.  Now you have to write 2 lines of code to attach an item from the library.  It is pretty simple.

AS3 code example - Attaching Item from Library

var item:item_one_mc = new item_one_mc();        //first declare library item
this.addChild(item);                                                      //add child to the stage

unloadMovie() has also been removed in AS3.  Instead of using unloadMovie(), you need to use removeChild().

AS3 code example - Removing Item from Stage

this.removeChild(item); 

The example below uses AS3 to attach an item from the library then remove it.



download as3_attachMovie_example

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments

Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.