Reputation: 815
How to name through AS3 buttons components?
I have 3 buttons components: a BackButton, a ForwardButton and a PlayButton.
I have named them through the properties panel, (where it says 'Instance Name').
But once I click on them and check for event.target.name I receive, always 'button_mc'.
How could I name the buttons?
Upvotes: 0
Views: 344
Reputation: 15955
If you set the property id from the properties panel, you should see it via the name property:
Here the switch block shows which button was clicked.
For 3 buttons named: backButton
, playButton
, and forwardButton
the following code will determine which was clicked.
import flash.events.MouseEvent;
backButton.addEventListener(MouseEvent.CLICK, clickHandler);
playButton.addEventListener(MouseEvent.CLICK, clickHandler);
forwardButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void
{
switch(event.target.name)
{
case "backButton":
trace("back button clicked");
break;
case "playButton":
trace("play button clicked");
break;
case "forwardButton":
trace("forward button clicked");
break;
}
}
Upvotes: 5