# Assigning unique variables to movieclip instances?

**URL:** <https://forum.kirupa.com/t/assigning-unique-variables-to-movieclip-instances/286138>\
**Category:** Uncategorized\
**Created:** [April 10, 2009, 5:14pm UTC](https://forum.kirupa.com/t/assigning-unique-variables-to-movieclip-instances/286138 "2009-04-10T17:14:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tugboat](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tugboat](https://forum.kirupa.com/u/tugboat)\
**Post date:** [April 10, 2009, 5:14pm UTC](https://forum.kirupa.com/t/assigning-unique-variables-to-movieclip-instances/286138/1 "2009-04-10T17:14:36Z")

</div>

This is a problem that has bugged me for a long time. I know there’s a solution, but I just can’t figure it out.

When one creates several instances of a movie clip on the main timeline, how can one assign separate variables to each of these instances and then invoke each of these values from the main timeline? I know how to do this by creating a separate movieclip and putting code on that movie’s timeline (using ‘this’), but I always feel this is sloppy because I’d like to keep my code all on one timeline.

Here’s some example code. It creates three instances of a movie clip, and assigns each one a variable called ‘contImage’ which contains the source of the loaded image. How can I get this variable traced when each of these images is clicked?

Thanks so much for anyone’s attention to this issue. Even though, as I said above, I have a work around, it has stuck in my craw for a while now.

```auto

var photos:Array = new Array('images/1.jpg', 'images/2.jpg','images/3.jpg');

for(var i:int = 0; i < photos.length; i++)
{
		var cont:MovieClip = new MovieClip;
		cont.x = i*100;
var contImage:String = new String;
		cont.contImage = photos*;
		addChild(cont);
		
		var loader:Loader = new Loader();
		loader.load(new URLRequest(photos*));
		cont.addChild(loader);
		
		cont.addEventListener(MouseEvent.CLICK, showImageSource);
		function showImageSource(e:MouseEvent)
		{
			// what code would I put here to trace the value of the variable 'contImage' (which is the source of the image)?
		}
		
}
			

```
