PDA

View Full Version : [AS2] Help With Spawning Movieclips


mesamec
06-23-2009, 02:22 PM
I'm making an RPG and I need to know how to spawn movieclips without too much complicated code. The mc i need to spawn is called money2.

bluemagica
06-23-2009, 02:26 PM
_root.attachMovie("money2","money2_1",this.getNextHighestDepth());

mesamec
06-23-2009, 02:34 PM
When I put that code into my frame it says ')' or ','.

Also how do I spawn it in random places on the stage?

rrh
06-23-2009, 10:03 PM
Bluemagica forgot to put his code in [ as ] tags, and the forum split getNextHighestDepth into two words. Remove the space.

random placement:
frank = attachMovie( ...
frank._x = Math.random()*WidthOfTheStage
frank._y = Math.random()*HeightOfTheStage

mesamec
06-24-2009, 07:44 AM
Umm I'm not very good at this but here is the code i put in, and it doesn't spawn anything.

_root.attachMovie("money2","money2_1",this.getNextHighestDepth());
frank = attachMovie("money2")
frank._x = Math.random()*WidthOfTheStage
frank._y = Math.random()*HeightOfTheStage


Lol sorry if I'm sort of newbish with these questions. Our tech teacher left our school so my friend and I can't ask him.

wnpang
06-24-2009, 07:51 AM
_root.attachMovie("money2","money2_1",_root.getNextHighestDepth());
frank = attachMovie("money2")
frank._x = Math.random()*WidthOfTheStage
frank._y = Math.random()*HeightOfTheStage

Try this first and now the new attached mc is called "money2_1" not "money2".

mesamec
06-24-2009, 08:22 AM
I put that code in to my AS frame and when I tested the game no coins spawned. Am I supposed to put the code somewhere else or is the code missing something?

bluemagica
06-24-2009, 11:44 AM
right click the money2 movieclip in your library, go to "Linkage" and give it a "instance name" of "money2".

then

var tempx = Math.round(Math.random()*200);
var tempy = Math.round(Math.random()*200);
_root.attachMovie("money2","money2_1",_root.getNextHighestDepth(),{_x:tempx,_y:tempy});