Heres a challenge for ya

look at this thread
http://www.kirupaforum.com/showthread.php?s=&threadid=6451
now the movie works which is great but i want to have a lot more balls. i could create 150 of them and give each an instance name but that would take forever.

is there a way to do this with actionscript.
i know i can duplicate a movie clip although i don’t know how to put them in that box formation like i have them in this movie but can i duplicate them into that formation and assign each an instance name that consists of a number so that when * is equal to their instance name the clip will play.

thanks

Have a look at this. If you create one instance of a object, just plact them in a colum, eg, a colum of ten, then it will tile along to the right, so do 100, you only need 1 column of ten. Look at it and you’ll understad. Someoen will probably come up with a more dynamic way of doing it (ahem, pom).

I’m working on your fla now to change it.

You don’t have to put the first tile there. You can create an empty movie clip and attach the tile to it.

I don’t have mx and can’t open the attached file but the code to duplicate is pretty straightforward in flash5

assume you want to make 150 balls from the MC instance “ball”

for (i=101;i<=250;i++) {
ball.duplicateMovieClip(“ball”+i,i)
}

this will create 150 clones of MC ball and give them the instance names ball151, ball152, ball153 … ball250

Why use values from 101 to 250 I hear you ask? Force of habit because invariably you’ll need to refer to the instances using a conditional for loop. If you know that your MC will always have a 3 digit identifier (which you’ll get from _name.substr(-3)) then it’s a lot easier to perform arithmetic operations.

So where were we? We’d just created 150 instances of ball and they’re all sitting on top of each other. But we want them all set out in a grid. No problem. Create an array containing the x and y coords of 150 clips. Sounds hellish - not really.

position one ball MC on the screen and add this code

onClipEvent (Load) {
trace(Math.floor(_x)+",“Math.floor(_y)”+",")
}

Now duplicate this clip 15 time (Ctrl+D) - tedious I know and align the clips vertically (Ctrl+K).

Next group these 15 clips (Marquee the Ctrl+G) and duplicate this group 10 times. Again align (Ctrl+K)

Then test (Ctrl+Enter)

You’ll get a nice long trace of 300 coords separated by commas. Hmm, looks a bit like an array, doesn’t it.

Select the trace (Ctrl+A) and copy it (Ctrl+C)

The define a new Array called something like coords

coords= new Array() and paste the trace between the () remembering to delete the comma after the last coord

Then finally all you need to do is place this code on the orignal instance instance of the movie clip and hide this clip off stage

onClipEvent (Load) {
if (_name!=“ball”) {
_x=_parent.coords.shift()
_y=_parent.coords.shift()
}
}

I’ve put the if in because I don’t want the original clip ball to reposition on stage because it won’t have a 3 letter numerical identifier.

I’m sure there’s a far more elegant way to do this in mx and doubtless someone post it …

I’ll post the fla again as Flash 5. You would have saved alot of typing. I used attachMovie instead of duplicate movie clip for this. And didn’t use an array for coords. There’s a simpler way of tiling/duplicating clips if it’s just columns and rows.