# Code targeting question?

**URL:** <https://forum.kirupa.com/t/code-targeting-question/10431>\
**Category:** Uncategorized\
**Created:** [December 31, 2002, 11:26pm UTC](https://forum.kirupa.com/t/code-targeting-question/10431 "2002-12-31T23:26:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceman](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@iceman](https://forum.kirupa.com/u/iceman)\
**Post date:** [December 31, 2002, 11:26pm UTC](https://forum.kirupa.com/t/code-targeting-question/10431/1 "2002-12-31T23:26:33Z")

</div>

hey everyone,

Here is my code:

for(i=0;i\<=12;i++){  
myCounter = “model” + i;  
model.duplicateMovieClip(myCounter, i);  
model.\_x = Math.round(Math.random() \* Stage.width);  
model.\_alpha = Math.round(Math.random() \* 100);  
model.\_xscale = Math.round(Math.random() \* 200);  
model.onRollOver = function() {  
myColor = Math.round(Math.random() \* 0xFFFFFF);  
myColorObject = new Color(model);  
myColorObject.setRGB(myColor);  
model.onRollOut = function(){  
myColorObject.setRGB(0x999999);  
}

```
}

```

}  
Everything works ok, but I was wondering why when I change model.\_x to myCounter.\_x the code doesn’t work. instead of targeting the original clip I’m targeting the duplicated clips but for some reason it doesn’t work at all. Same thing happens when I try and add the roll over function to the duplicated instances, so instead of model.onRollOver I would like myCounter.onRollOver but it won’t work. If anyone could help me it would be great, I’m just trying to figure out what the difference is. Thanks A Lot

Kyle  
Happy New Year!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 31, 2002, 11:41pm UTC](https://forum.kirupa.com/t/code-targeting-question/10431/2 "2002-12-31T23:41:30Z")

</div>

myCounter, because you declared it to be a string at the beginning of the script remains a string and doesnt represent the actual movieclip that was created. Its only its name as a string. To reference the actual movieclip, you can use either

eval(myCounter)

or

this[myCounter]

so youll have something like

```auto

for (i=0; i<=12; i++) {
	myCounter = "model"+i;
	model.duplicateMovieClip(myCounter, i);
	this[myCounter]._x = Math.round(Math.random()*Stage.width);
	this[myCounter]._alpha = Math.round(Math.random()*100);
	this[myCounter]._xscale = Math.round(Math.random()*200);
	this[myCounter].onRollOver = function() {
		myColor = Math.round(Math.random()*0xFFFFFF);
		myColorObject = new Color(this);
		myColorObject.setRGB(myColor);
		this.onRollOut = function() {
			myColorObject.setRGB(0x999999);
		};
	};
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 1, 2003, 12:10am UTC](https://forum.kirupa.com/t/code-targeting-question/10431/3 "2003-01-01T00:10:32Z")

</div>

Thanks Alot, that worked perfectly, I appreciate the help.

Thanks

Kyle
