Monday, 6 July 2009

AttachMovie in Actionscript 3

The attachMovie method in Actionscript 2.0 has now been removed and replaced with the addchild in Actionscript 3.0. Below is a comparison of the two versions.

AS2

attachMovie("my_movie", "movie", 1);

AS3

var movie:MovieClip = new my_movie();
addChild(movie);

As you can see above the in AS2 the linkage ID is “my_movie”, whereas in AS3 the class name is “my_clip”. The process for dynamically adding a movie/button on the stage in AS3 is very similar to the previous AS2. Below I will show you how to attach a movie clip on the stage in Actionscript 3.0.


AttachMovie in Actionscript 3

Step 1

Open a new Flash AS3 file.
On the menu bar select Insert > New Symbol then give your symbol an appropriate name, select
movie clip, check Export to Actionscript and click ok.



When you check the Export to Actionscript, the class name and base class gets fills in automatically. The base class means the properties and methods get assigned to the movie clip class.


Step 2

Create an object on the stage I have created a simple rectangle shape, but you can whatever you wish. Now return to the main stage by selecting the back button.


Step 3

Select F9 to open up the actions panel and add the following code:

var rectangle:MovieClip = new my_rectangle();
addChild(rectangle);


Step 4

Test your movie clip Ctrl + Enter. The rectangle shape should now appear at the (0,0) position on the stage. The steps above assume you have no movie clips initially in the library. If you have a movie clip in the library you can right click on it and select properties. Then check the Export to Actionscript and click ok.

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP