Skip to main content
Known Participant
August 22, 2011
Answered

Make a new instance of an existing symbol (movie clip or graphic) using AS3

  • August 22, 2011
  • 1 reply
  • 1727 views

I want to make a new instance of an existing symbol (movie clip or graphic) when an object hits the side of the stage. I have the code to figure out if it hit the side of the stage, i just need to know how to make a new instance and make it show up where the ball hit. I also want to be able to have multiple of these instances on screen. thanks in advance, i'm sure it's a basic thing, i'm just really new to flash, so yeah.

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

First create the symbol as a movieclip.  Then right click the object in the library and select the Linkage option.  In the panel that opens select the option to export for actionscript and then assign a Class name for the symbol... lets say you name it ImageMC (caps are usually used for starting class names).  Flash will provide an indication that it can't find a class and it will create one when you compile.

To add a new instance of the symbol to the stage you use...

var imgMC:ImageMC = new ImageMC();

imgMC.x = ???;

imgMC.y = ???;

addChild(imgMC);

where the x and y values (???) will be determined based on whatever information you have available regarding where the ball was when it hit the wall.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 23, 2011

First create the symbol as a movieclip.  Then right click the object in the library and select the Linkage option.  In the panel that opens select the option to export for actionscript and then assign a Class name for the symbol... lets say you name it ImageMC (caps are usually used for starting class names).  Flash will provide an indication that it can't find a class and it will create one when you compile.

To add a new instance of the symbol to the stage you use...

var imgMC:ImageMC = new ImageMC();

imgMC.x = ???;

imgMC.y = ???;

addChild(imgMC);

where the x and y values (???) will be determined based on whatever information you have available regarding where the ball was when it hit the wall.

Known Participant
August 23, 2011

will this work to make multiple ones, all using the exact same code, not changing the name at all?

Known Participant
August 23, 2011

Great!!! thank you, it worked great!

one other question though, how would i get the objects to move down the screen after they have been made?