-
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?
-
.
Hi,
Try
PHP Code:
this["molecule" + i].onMouseDown
-
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.
-
.
Hi,
For you to reference each attached clip/button try
PHP Code:
this["molecule" + i].Num = i; this["molecule" + i].onPress = function() { trace("you clicked molecule" + this.Num); };
Last edited by fruitbeard; 07-02-2013 at 07:56 AM.
Reason: typo
-
Thank you Fruitbeard! It worked! I owe you my life sir!
-
.
Hi,
I sent a private message to your other question, but not sure if it was sent or not!!
But here is your answer
PHP Code:
_root.gp.control.onRelease = function()
{
for (var j = 0; j < molecules.length; j++)
{
_root["molecule" + j].removeMovieClip();
//this["molecule" + j].removeMovieClip();
}
};
one of those will work depending where you have the stuff embedded.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|