Code targeting question?

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!!!

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


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

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

Thanks

Kyle