Adding movieclips from library

Subscribe to Adding movieclips from library 2 posts

avatar for susha susha 2 posts
Flag Post

Hey im wondering how to add multiple movieclips from the library at a random location when you press a button in timelinecode, and how to remove the movieclips with a press of another button

 
avatar for DrYoshiyahu DrYoshiyahu 678 posts
Flag Post

Go to the properties of the movieclip and click “export for actionscript”
In AS2, you would give it an identifier.
In AS3 you would give it a Class name.

Then in AS2 you would write:

var object = _root.attachMovie("identifierName", "objectName", depth);
object._x = Math.random()*Stage._width;
object._y = Math.random()*Stage._height;

In AS3 you would use:

import flash.display.MovieClip;

var object:className = new className;
addChild(object);
object.x = Math.random()*550;
object.y = Math.random()*400; //I'm not sure of the exact term for stage height/width in AS3

To add multiple objects you could use a for loop…

//AS2:
for (var i=0; i<10; i++) {
    var object = _root.attachMovie("identifierName", "objectName"+i, depth+i);
    object._x = Math.random()*Stage._width;
    object._y = Math.random()*Stage._height;
}

//AS3:
var object:className;
for (var i=0; i<10; i++) {
    object = new className;
    addChild(object);
    object.x = Math.random()*550;
    object.y = Math.random()*400;
}