Hey there- I'm attempting to write a hierarchy app via an xml file. So if I had an xml file like this:
<block>
<block/>
<block/>
</block>
I want it to generate a vertical layout like so:
[ block ]
[ block ][ block ]
I'm successful in writing a tree menu horizontally (see code below) but not vertically. Any suggestions would be helpful!
import flash.display.Sprite;
var xml:XML =
<block>
<block/>
<block/>
</block>;
var count:int = 0;
function tree(node:XML, depth:int = 0):void {
count++;
ui(node.localName(), depth);
//recursive
node.*.(tree(valueOf(), depth + 1));
}
var mainCont:Sprite = new Sprite();
addChild(mainCont);
var padding:int = 20;
//draws the textfield and positions it.
function ui(text:String, depth:int):void {
var cont:Sprite = new Sprite();
mainCont.addChild(cont);
cont.graphics.beginFill(0x000000, .2);
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = text;
cont.addChild(tf);
cont.x = depth * cont.width;
cont.y = (count - 1) * (tf.width + (padding));
cont.graphics.drawRect(0,0,tf.width + padding,tf.height + padding);
cont.graphics.endFill();
tf.x = (cont.width * .5) - (tf.width * .5);
tf.y = (cont.height * .5) - (tf.height * .5);
}
tree(xml);