-
Instance names getting changed!
Hi chaps,
I know I've read something about this here before but I can't find it, so for Mr. Thicky here, can someone go over this one more time for me please .....
I have dragged some buttons on my stage - each one is actually an instance of the same movieclip. In the IDE, I have given them instance names like 'myButton1', 'myButton2' etc. I've then grouped all these buttons together into a single container movieclip called 'buttonHolder'.
Now, in my code, I am trying to retrieve the instance name of the button I have clicked on:
Code:
buttonHolder.addEventListener(MouseEvent.CLICK,clickHandler);
function clickHandler(e:MouseEvent):void{
trace(e.target.name);
The problem is, rather than tracing the instance names I gave to the buttons in the IDE like 'myButton1', it has created its own instance names called 'instance1', instance2', etc. I don't think it usually does this - in fact I'm sure I did this recently and got the original instance names.
Any help greatly appreciated as always,
Cheers,
Ric.
-
Senior Member
you have to name your buttons using mybutton1.name = "mybutton1";
then trace(e.target.name );
-
If your clip has stuff inside it, then the actual target could be something inside each button rather than the button. You can set mouseChildren=false on each button to prevent the children from dispatching their own MouseEvents.
-
Ah - yes that is what was happening - it was clicking through to a child object which didn't have instance name already. Setting mouseChildren works for returning the correct instance name, but prevents the button from showing it's mouse over state.
However, now that I know what is happening, I've been able to solve it by referencing e.target.parent.name which gives the correct instance name.
Thanks for your help guys.
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
|