views:

41

answers:

2

I've created an amount of MC based on my XMLlist, and each assign with an attribute/ID stated in the XML. I'm now trying to trace back the parent of the assigned MC properties, how could I do that?

The XML:

<MEMBER NAME="Todd" ID="001">
     <MEMBER NAME="Popia" ID="003">
     </MEMBER>
     <MEMBER NAME="Popia2" ID="004">
      <MEMBER NAME="Awesome" ID="005">
      </MEMBER>
     </MEMBER>
</MEMBER>

And here'es the Actionscript

private function Members():void {

  //trace(myXML.children().attribute("ID"));

  xmlList=myXML.children();

  for each (myXML in xmlList) {

   circles.x=Math.floor(Math.random()*100)-50;
   circles.y=Math.floor(Math.random()*100)-50;

   circles.buttonMode=true;
   circles.addEventListener(MouseEvent.CLICK, clickTarget);

   addChild(circles);
   circles.name=myXML.attribute("ID");
  }
 }



 private function clickTarget(event:MouseEvent):void {
  //trace(event.target.name);
  //trace(event.target.parent().attribute("ID"));
//trying to trace previous assgined att MC position
  trace("click");
 }
A: 

You are changing the same object (namely circles) in every iteration of the for each loop. You might wanna change that.

event.target.name will trace the name of the circles object. To get its parent's name, trace(event.target.parent.name).

Good practice is to cast event.target to MovieClip and store it in a local variable. This way you will get code hinting (in flex builder at least) and compiler's type checking.

Amarghosh
A: 

you will have to make a loop that goes through your XML hirearchy and attaches your new movieclip in the right place, at the moment you are adding the circles to the stage directly rather than in the hirarchical order of the XML. you are also needing to make a circles = new Class() call to make a new object

shortstick