Michael
Michael

Reputation: 337

AS3 - Get MovieClip instance name onClick

I've a row of MovieClips with the instance names holder0 to holder7. How can I get the holder name of the MovieClip by click?

Thanks for tips.

Upvotes: 2

Views: 13237

Answers (1)

Corey
Corey

Reputation: 5818

Something like this:

var mc:MovieClip;
for (var i:int = 0; i<8; i++) {
    mc = this["holder"+i];
    mc.buttonMode = true;
    mc.mouseChildren = false;
    mc.addEventListener(MouseEvent.CLICK, clickHandler);
}

function clickHandler(e:MouseEvent):void {
    trace(e.target.name);
}

Upvotes: 7

Related Questions