views:

28

answers:

2

I'm trying to know the MC I clicked, is from which line of code in my XML files.

for (var i:Number=0; i<myXML.children().length(); i++) {
addChild(someMC)
}

someMC.addEventListener(MouseEvent.click,clicky)
A: 

im not really sure what you're asking but as far as i can tell you're trying to figure out which movie clip fired a click event.

var len:Number = myXML.children().length()
for(var i:uint = 0; i < len; ++i) {
  var someMC:MovieClip = new MovieClip();
  addChild(someMC);
  someMC.addEventListener(MouseEvent.CLICK, clicky);
}

private function clicky(e:MouseEvent) :void {
  var theMCThatFiredTheEvent:MovieClip = e.currentTarget;
}
greg
A: 

event.target and event.currentTarget properties hold references to the object that was clicked. Specifically, target contains the exact child that was clicked on and the currentTarget contains the object with which event handler was registered. For example, if you call addEventListener on someMC and the user clicks on a button that is a child of someMC, event.target would be the button and event.currentTarget would be someMC itself.

function clicky(e:MouseEvent):void
{
  var clickedMC:MovieClip = MovieClip(e.currentTarget);
}

You are addchilding the same object throughout the loop and calling addEventListener outside the loop - hope that's not the real code.

Amarghosh