views:

49

answers:

2

Currently I only manage to traced the last MC. How could I trace the correct MC properties?

private function levelsBG():void {

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

   listText=new TextField  ;
   listMC=new MovieClip  ;
   listText.text=myXML.MEMBER[i].@NAME;

   listMC.buttonMode=true;
   listMC.mouseChildren=false;
   listMC.addChild(listText);
   addChild(listMC);

   listMC.addEventListener(MouseEvent.MOUSE_OVER,listOver);
  }
 }
 private function listOver(e:MouseEvent):void {
  trace(e.target.parent.listText.text);
 }
A: 

Since you are not changing their positions (x & y), each mc would appear on top of the previous one. Since all movieclips are of same size and the last one is on the top, only that mc will receive the mouseOver event. Change their position in the loop using something like mc.x = i * WIDTH;

Amarghosh
i did have the mc.x=width*i kind of script there, but seems like every listText is using listMC as the holder instead of separate listMC
Hwang
Are all text fields displayed at different locations?
Amarghosh
yup. after some searching and toughts my correct question would be how to make a duplicate button functionable individually?
Hwang
A: 

Well, it looks like you're doing something kind of screwy here.

It appears that, due to listText not being declared in the levelsBG function, it must be declared out at the class level, and you are overwriting a reference to that object in every iteration through your loop, so the only one that exists at the end, is the very last object created.

Then in your event handler, you are traversing up the display tree to the class in which that one reference lives, and tracing out the text of that one, so the appearance is that they are all the same.

If your intent is to trace the 'text' property of any given textfield that you've named listText, you will need to go about it a little differently. This snippet should work, but you might want to revisit your understanding of how class members work and can be addressed, as opposed to child DisplayObjects?

private function levelsBG():void {

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

                    listText=new TextField  ;
                    listMC=new MovieClip  ;
                    listText.text=myXML.MEMBER[i].@NAME;
                    listText.name = "listText";

                    listMC.buttonMode=true;
                    listMC.mouseChildren=false;
                    listMC.addChild(listText);
                    addChild(listMC);

                    listMC.addEventListener(MouseEvent.MOUSE_OVER,listOver);
            }
    }
    private function listOver(e:MouseEvent):void {
            trace(e.target.getChildByName("listText").text);
    }

}
JStriedl