views:

32

answers:

1

I have a loop MC which will be duplicate to stage several times according to every click. Now I want to detect if the MC being click belongs to which position in the array.

private function levelsBG():void {

  LIST = new MovieClip();
  d++;

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

   listMC=new MovieClip();


   LIST.addChild(listMC);

   listMC.addEventListener(MouseEvent.CLICK,listClick);
  }

  listArray.push(LIST);
  LISTmc.addChild(LIST);
  addChild(LISTmc);

  }

private function listClick(event:MouseEvent):void {
  var currentListArray=listArray[listArray.length-1];

  //trace from which position of Array
  trace(listArray.length-event.target.parent)
 }
A: 

why do you lookup the parent? maybe use mouseChildren = false, so event.target points to you clip ... to find the index, use Array::indexOf, so should be something like trace(listArray.indexOf(event.target)) in the end ...

greetz

back2dos

back2dos
trace(listArray.indexOf(event.target)) return -1so i use trace(listArray.indexOf(event.target.parent)) thanx! =D
Hwang