Skip to main content
magblack22
Known Participant
May 3, 2011
Answered

Multiple instances of one Movieclip

  • May 3, 2011
  • 1 reply
  • 2565 views

Hi! I'm trying to do a drag and drop game, where I have to drag the same movieclip several times...

can anyone please help me?? how can i do that??

Thanks!!!

This topic has been closed for replies.
Correct answer Ned Murphy

You'll have to create new instances of the movieclip.  To do that, right click the movieclip in the library and select Linkage.  In the window that opens up select the Export forActionscript option and the movieclip's library name will appear where it says "Class"... change that to whatever you like (classes are normally named with a leading capital letter)... let's say you assign it a class name of "MyMC"

To create a new instance what you need to do is use:

var newMC:MyMC = new MyMC();

addChild(newMC);

and then you'll have to asign whatever event listeners and whatnot you need for what you plan to do with it.

1 reply

Ned Murphy
Legend
May 3, 2011

Assign MouseEvent.MOUSE_DOWN / MOUSE_UP event listeners that call upon the the startDrag() / stopDrag() methods of the movieclip(s).

If you need example code, you should be able to find some if you Google "AS3 startDrag tutorial"

magblack22
Known Participant
May 3, 2011

mmm.... i don't have a problem with the drag part...

what i have to do, is....

- i have a mc on stage and i have to be able to drag the same movie several times and position it around the stage.... but it's the same movieclip... so, what i was wondering is if there's a way to 'duplicate' that movieclip, so that i can have several of them at the same time

Thanks very much!!

Ned Murphy
Ned MurphyCorrect answer
Legend
May 3, 2011

You'll have to create new instances of the movieclip.  To do that, right click the movieclip in the library and select Linkage.  In the window that opens up select the Export forActionscript option and the movieclip's library name will appear where it says "Class"... change that to whatever you like (classes are normally named with a leading capital letter)... let's say you assign it a class name of "MyMC"

To create a new instance what you need to do is use:

var newMC:MyMC = new MyMC();

addChild(newMC);

and then you'll have to asign whatever event listeners and whatnot you need for what you plan to do with it.