onMouseDown listener to an attachMovie; harder than you think.
Heres the gist of my problem...
- A Grid is filled out with molecules, using a loop;
- User clicks on molecule to bring up its virtual co-ords
Now i have a loop:
Code:
for (var i = 0; i < _root.gp.input; i++)
{
// Makes a new instance of the MC "Molecule"
this.attachMovie("Molecule","molecule" + i,i);
// Add a listener to the new molecule
(molecule + i).onMouseDown = function()
{
trace("you clicked " + "molecule" + i);
};
}
This is the tricky bit -> ("molecule" + i).onMouseDown = function()
How can i attach code to a new instance of a movie?
UPDATE - Still not working
Using this code:
Code:
// Show Coordinates
this["molecule" + i].onMouseDown = function()
{
trace("you clicked " + "molecule" + i);
};
and the Trace Output is:
Code:
you clicked molecule5
you clicked molecule5
you clicked molecule5
you clicked molecule5
you clicked molecule5
So ive made 5 instances of the movieclip (0 to 4), and clicking on any shows the ("molecule" + i) where i is the incrementer in the loop, and 5 is the defined delimiter.
I need to make any molecule be identified when clicked on. So the value should be unique, not the same regardless of which molecule like it currently is.
Thanks in advance anyone who reads this post or offers a hand.