[CS3] AS/2 Naming dynamic movieClips Individually


for(var i=0;i<10;i++){
    var skeet:MovieClip = attachMovie("skeet", "skeet" + i, i);
    //position randomly
    skeet._x = Math.random()*500+20;
    skeet._y = Math.random()*360+20;
    //how much he can eat
    skeet.capacity = 10;
    //how fast he is (higher number = slower movement)
    skeet.speed = 10;
    // start with an empty stomach
    skeet.ate = 0;
    skeet.onEnterFrame = eat;
}

Hi i have a for loop that creates 10 of my skeet movieclips at random positions on the stage.

I then have a hitTest that traces a 1, to the output window if the skeet movieClip hits my food movieclip. My variables are then sent thru my server.

However i need to know which skeet out of the ten is hitting the food at that given time.
So that when skeet 1 hits food it sends variable 1 and traces a 1, the same for 2 and so on.

So basically i need to know how to name dynamic movie clips individually, or give them a variable name that they trigger upon creation. Thanks for any advice in advance.

 

if (this.hitTest(skeet)) {
        trace(["1"]);
        max.send("; var1 1;");
        max.send("; var2 1;");
        max.send("; var3 1;");
        max.send("; var4 1;");
        max.send("; var5 1;");
        max.send("; var6 1;");
        max.send("; var7 1;");
        max.send("; var8 1;");
        max.send("; var9 1;");
        max.send("; var10 1;");
   } else {
        max.send("; var1 0;");
        max.send("; var2 0;");
        max.send("; var3 0;");
        max.send("; var4 0;");
        max.send("; var5 0;");
        max.send("; var6 0;");
        max.send("; var7 0;");
        max.send("; var8 0;");
        max.send("; var9 1;");
        max.send("; var10 0;");
     }
  };


easy way is dynamically create them, the read a variable into or use the items name, to get the variable, which will hence tell you on hittest which ID it is

for (i=0;i<5;i++){
attachMovie(“the” “the”+ i, i+1)
[“the”+i].id = i

}

the above is not real code :stuck_out_tongue:

Works with my swf? How is it not real? I have not given the whole script just a snippet. I can upload the full .fla if that helps?

Hey man not sure i undertsand your response, im quite new too all this, so you think naming them dynamically is way to go?

where is your hitTest() code at… is that in the function eat?

naming dynamically is the standard.

“but”+ i … creates a UID or “unique identifier”

you can either give its and .id = i property

or strip the number from the name with

input = String(this)
subString()
subString()
adjust code
find number

… search my posts I gave a more informed answer not that long ago to someone else

from the looks of it you already have called them

“skeet” + i

so you would have

this[“skeet”+i].onRollOver = function(){
get ID of this item
run code using this ID

}

I’m unsure about hittest, but your question was how do I figure out UID and the above is it :stuck_out_tongue: