Help with duplicateMovieClip

Hi:

And I´m trying to make an arkanoid clon and have a some problems,
instead of 100 instances I only get 20, can anyone tell me where is the mistake.
I hope you can help me

best regards

nicolas nadjar

//create the arrays

equis=new Array(10);
ygriega=new Array(10);

//x and y coords

for(i=1;i<=10;i++){equis*=47i;}
for(j=1;j<=10;j++){ygriega[j]=15
j;}

// make the rectangles

for(i=1;i<=10;i++){
for(j=1;j<=10;j++){
_root.obstaculo.duplicateMovieClip (“obstacul”+i+j, i+j );
_root[“obstacul”+i+j]._x= equis*;
_root[“obstacul”+i+j]._y= ygriega[j];

//note : rectangle´s dimensions: 44 by 12 pixels

//

			}}:q:

Try this:


//create the arrays
equis=new Array(10);
ygriega=new Array(10);

//x and y coords
for(i=0;i<10;i++){equis*=47*i;}
for(j=;j<10;j++){ygriega[j]=15*j;}

// make the rectangles
for(i=0;i<=10;i++){
  for(j=0;j<=10;j++){
    _root.obstaculo.duplicateMovieClip ("obstacul"+i+j, Number(i.toString()+j.toString()) );
    _root["obstacul"+i+j]._x= equis*;
    _root["obstacul"+i+j]._y= ygriega[j];

    //verify properties
    trace("Name:     "+_root["obstacul"+i+j]._name);
    trace("_x:       "+_root["obstacul"+i+j]._x);
    trace("_y:       "+_root["obstacul"+i+j]._y);
    trace("_visible: "+_root["obstacul"+i+j]._visible);
    rectCount+=1;
    trace("rectCount:"+rectCount);
    //note : rectangle´s dimensions: 44 by 12 pixels
    
  }
}

I’ll explain what I changed.

First of all, you declare a new array with 10 elements. The elements are numbered starting from 0, not 1, as you had it. So they would go from [0] to [9] (that’s 10 total). So I fixed your ‘for’ loops to reflect this.

Second, you were duplicating the movieclips into layers that were already populated at times. For example, when i=0, and j=0, then you would have a clip in level0. Then, when i=0, and j=1, you would have a clip in level1. No problems so far. But when we get to i=1, and j=0, the level is level1 again, so the new clip replaces the old one at level1. So I basically took your i and j values, converted them to strings, concatenated the string, then converted the string to a number, so you’d get: 00, 01, 02…97, 98, 99 (that’s 100 levels and 100 clips).

Hope it works now. If you have any other questions just ask. :slight_smile:
-Al

I have a game that I’ve attached this code to a laser:

if (this.hitTest(_root[“enemy”+i]))

that will hit each duplicated “enemy” ship, I’ve incremented with “i”. Hope this helps you, toothpick, if you’re still checking here for your answer.