all groups > flash actionscript > june 2004 >
You're in the

flash actionscript

group:

Creating Instance of Clip from Library with Action


Creating Instance of Clip from Library with Action Drauka36s
6/2/2004 10:17:31 PM
flash actionscript:
I'm using Macromedia's Flash 5 (I'm a little behind the times), and I'm trying
to create a Flash game. To do this, I need to be able to create instances of
objects, and I'm trying to do it without duplicating already existing objects.
Anyone have any ideas?

Thanks in advance,
Drauka~
Re: Creating Instance of Clip from Library with Action gorlins
6/3/2004 12:40:40 AM
I dont know for sure this will work in Flash 5, it does in 6 and 7. use
this.attachMovie("MyLibraryClip", "myNewInsanceName", depth [, initObject]).

So if you have a movie clip in your library, go to properties and check
"export for actionscrip" and "export in first frame" and make sure it has the
appropriate name for export. When you attach it make sure each instance gets a
unique depth, and use the init object if you want to control position, scale,
etc IE:

depthCounter = 0;
myObject = new Object();
myObject._x = myObject._y = 100;
_root.attachMovie("libraryMC", "instanceName", depthCounter++, myObject);

this creates an instance at (100,100)

Note that the brakets around initObject in the function definition make the
object optional, so you don't have to use it if you want to create the instance
with default parameters
AddThis Social Bookmark Button