user3180774
user3180774

Reputation: 33

Tracing XML child

I want to trace one button element at a time. But not only the content of the button.

I would like to get to trace:

 <BUTTON XY="100,300" TOMAP="SECOND" WARLEVEL="02_deamon" REQUIRE="03_cityMonsters" UNTIL="04_chaosBlaBla">Description1...</BUTTON>

However, I know the button does contain the data, as it traces REQUIRE. The problem is only the tracing-part. Either it traces too much as map.toString() does, or too little as button.toString() does.

In flash:

...
var map:XML = world.MAP[_map];

trace(map.toString());

does what I want, traces:

<MAP NAME="FIRST">
     <BUTTON XY="100,300" TOMAP="SECOND" WARLEVEL="02_deamon" REQUIRE="03_cityMonsters" UNTIL="04_chaosBlaBla">Description1...</BUTTON>
     <BUTTON XY="100,400" TOMAP="FIRST" WARLEVEL="03_cityMonsters" REQUIRE="03_cityMonsters" UNTIL="04_chaosBlaBla">Description2...</BUTTON>
     <BUTTON XY="200,300" TOMAP="PREBOSS">GO-TO STUFF</BUTTON>
     <BG>backgrounds/firstBg.jpg</BG>
</MAP>

but

for (var i = 0; i < map.BUTTON.length(); i++) {

    var button:XML = map.BUTTON[i];
    if (button.@REQUIRE != undefined) {
        trace("found REQUIRE ");  // Traces: found REQUIRE 
    }
    trace(button.toString());

}

Does NOT do what I want, traces:

Description1...

XML-File:

<WORLD>
  <MAP NAME="FIRST">
    <BUTTON XY="100,300" TOMAP="SECOND" WARLEVEL="02_deamon" REQUIRE="03_cityMonsters" UNTIL="04_chaosBlaBla" >Description1...</BUTTON>
    <BUTTON XY="100,400" TOMAP="FIRST"  WARLEVEL="03_cityMonsters"  REQUIRE="03_cityMonsters" UNTIL="04_chaosBlaBla" >Description2...</BUTTON>
    <BUTTON XY="200,300" TOMAP="PREBOSS" >GO-TO STUFF</BUTTON>

    <BG>backgrounds/firstBg.jpg</BG>
  </MAP>
  <MAP NAME="SECOND">
    <BUTTON XY="100,300" TOMAP="FIRST"  WARLEVEL="03_cityMonsters"  REQUIRE="03_cityMonsters" UNTIL="04_chaosBlaBla" >Description3...</BUTTON>
    <BUTTON XY="100,250" TOMAP="SECOND" >Description4..</BUTTON>
    <BG>backgrounds/firstBg.jpg</BG>
  </MAP>
</WORLD>

Upvotes: 3

Views: 78

Answers (1)

Tim
Tim

Reputation: 2151

Try toXMLString()

trace(button.toXMLString());

Upvotes: 2

Related Questions