Howdy - I need to draw outlines of the footprints of n buildings that are
described in an xml file which I'm reading into FMX Pro. I'm loading the xml,
looping thru it, finding the node which holds the x/y coords (pipe delimited
list) all without problem. The problem is that I can't get the stinkin'
ActionScript to actually draw the footprint(s)! Aaaaarg!!
Basically, here's the process:
1. load xml
2. loop thru each building element
3. For each building, create an empty movieclip which will hold the drawing of
the building footprint outline
4. for each building, find coordinates node, parse pipe-delimited list
5. loop thru coordinates list (moveTo() first element, then lineTo()
remaining elements) drawing outline in this building's movieclip
If anyone can help me over this last hurdle (the stinkin' footprint not
drawing), I'd greatly appreciate it!
ActionScript:
//create the XML object
var myXML:XML = new XML();
myXML.ignoreWhite = true;
//create the event for when the XML object loads content
myXML.onLoad = function(success){
if(success){
//start walking the Building XML tree
for (var i:Number = 0; i < this.firstChild.childNodes.length; i++) {
//create a new building movieclip that will hold outline of building
footprint
var thisBuilding_mc:String = "thisBuilding_mc_" + i;
this.createEmptyMovieClip(thisBuilding_mc, 20 + i);
//search thru each building's nodes
for (var j:Number = 0; j <
this.firstChild.childNodes[i].childNodes.length; j++) {
//get the name:value pair of each node within a building
var nodeName:String = this.firstChild.childNodes[i].childNodes[j].nodeName;
var nodeValue:String =
this.firstChild.childNodes[i].childNodes[j].childNodes[0].nodeValue;
//trace(nodeName+"="+nodeValue);
//we need to do special processing with the <coordinates></coordinates>
node
if (nodeName == "coordinates"){
//establish an array holding each x/y coordinate for this building's
footprint
var my_str:String = nodeValue;
var my_array:Array = my_str.split("|");
//next draw the footprint within the movieclip we created for this
building
with(thisBuilding_mc) {
//loop thru the x/y position array
for (var i = 0; i<my_array.length; i++) {
trace(my_array[i]);
//start drawing the outline - if it's the first array element we
"moveTo()" otherwise "lineTo()"
lineStyle(1,0x000000,this.getNextHighestDepth());
if (i == "0") {
trace(thisBuilding_mc); moveTo(nodeValue);
}
else {
lineTo(nodeValue);
} //end if()
} //end with()
} //end if()
} //end for (j..)
} //end for(i..)
} //end if(success)
} else {
trace("There was a major error.");
}
} //end xml.onLoad()
//now load the content
myXML.load("siteplan.xml");
XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<phase>
<building>
<buildingID>1</buildingID>
<name>Blackbear Lodge</name>
<status>now taking reservations</status>
<image>
http://cardel.aumenta.net/gondolaplaza/images/elevation_thumb.jpg</ima
ge>
<units>54</units>
<levels>4</levels>
<priceRange>$250 - $640k</priceRange>
<coordinates>232,275|249,268|251,275|257,271|272,278|275,276|284,280|310,293|
298,324|258,307|246,311|237,311|237,331|210,317|232,375</coordinates>
</building>
<building>
<buildingID>2</buildingID>
<name>Glacier Lodge</name>
<status>sold out</status>
<image>
http://cardel.aumenta.net/gondolaplaza/images/elevation_thumb.jpg</ima
ge>
<units>54</units>
<levels>4</levels>
<priceRange>$250 - $640k</priceRange>
<coordinates>232,275|249,268|251,275|257,271|272,278|275,276|284,280|310,293|
298,324|258,307|246,311|237,311|237,331|210,317|232,375</coordinates>
</building>
</phase>