# \[CS3\] AS/2 Naming dynamic movieClips Individually

**URL:** <https://forum.kirupa.com/t/cs3-as-2-naming-dynamic-movieclips-individually/262492>\
**Category:** Uncategorized\
**Created:** [June 6, 2008, 11:31am UTC](https://forum.kirupa.com/t/cs3-as-2-naming-dynamic-movieclips-individually/262492 "2008-06-06T11:31:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daky](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Daky](https://forum.kirupa.com/u/Daky)\
**Post date:** [June 6, 2008, 11:31am UTC](https://forum.kirupa.com/t/cs3-as-2-naming-dynamic-movieclips-individually/262492/1 "2008-06-06T11:31:05Z")

</div>

```auto

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.

```auto
 

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;");
     }
  };

```

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 6, 2008, 11:40am UTC](https://forum.kirupa.com/t/cs3-as-2-naming-dynamic-movieclips-individually/262492/2 "2008-06-06T11:40:35Z")

</div>

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 😛

---

<div class="post-metadata">

**Author:** ![Daky](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Daky](https://forum.kirupa.com/u/Daky)\
**Post date:** [June 6, 2008, 1:18pm UTC](https://forum.kirupa.com/t/cs3-as-2-naming-dynamic-movieclips-individually/262492/3 "2008-06-06T13:18:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Daky](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Daky](https://forum.kirupa.com/u/Daky)\
**Post date:** [June 6, 2008, 10:53pm UTC](https://forum.kirupa.com/t/cs3-as-2-naming-dynamic-movieclips-individually/262492/4 "2008-06-06T22:53:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [June 9, 2008, 1:59am UTC](https://forum.kirupa.com/t/cs3-as-2-naming-dynamic-movieclips-individually/262492/5 "2008-06-09T01:59:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 9, 2008, 9:42am UTC](https://forum.kirupa.com/t/cs3-as-2-naming-dynamic-movieclips-individually/262492/6 "2008-06-09T09:42:36Z")

</div>

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 😛
