On runtime, I create multiple instants of the Group class, like this:
var groupArtist:Group = new Group();
groupArtist.id = artistXML.id;
groupArtist.width = 150;
groupArtist.height = 170;
groupArtist.clipAndEnableScrolling = true;
groupArtist.layout = new VerticalLayout();
I add an eventlistener:
groupArtist.addEventListener(MouseEvent.CLICK, viewDetails);
This is the eventlistener:
private function viewDetails(event:MouseEvent):void
{
Alert.show(event.target.id);
}
But it’s not working. How can I get the id of the clicked Group?
I’ve checked, and the Id is added correctly to the groupinstances.
Try this:
What you’re alerting is the “target” that was clicked, and associated in the “MouseEvent.CLICK” event, and you probably want the “currentTarget”. As Flex Documentation explains on this, “Every Event object has a target and a currentTarget property that help you to keep track of where it is in the process of propagation. The target property refers to the dispatcher of the event. The currentTarget property refers to the current node that is being examined for event listeners.“.
The Most Interesting Man in the World doesn’t normally code in Actionscript… but when he does, he uses event.currentTarget.