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;
}
|