Hi everyone,
[LEFT]I’ve just recently read the tutorial Using XML in Flash CS3/AS3
And I started building a little menu that is supposed to attach movieclips according to the structure of the XML, like a directory structure in windows explorer.
The code looks like this :d: :
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("domains.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParseDom(xmlData);
}
function ParseDom(domainInput:XML):void {
var yPos:int;
for each (var domainInfo:XML in domainInput.domain.title) {
var item:MovieClip = new Item();
if (domainInfo.name() == "title") {
item.domain_text.text = domainInfo;
}
item.y = yPos;
yPos = item.height;
item.buttonMode = true;
item.mouseEnabled = false;
var container:Sprite=new Sprite();
container.y = yPos;
for each (var subdomainInfo:XML in domainInput.domain.subdomain.title) {
var subitem:MovieClip = new subItem();
if (subdomainInfo.name() == "title") {
subitem.subdomain_text.text = subdomainInfo;
}
subitem.y = yPos;
yPos = container.height;
for each (var publisherInfo:XML in domainInput.domain.subdomain.publisher.title) {
var publisher:MovieClip = new publisherItem();
if (publisherInfo.name() == "title") {
publisher.publisher_text.text = publisherInfo;
}
publisher.buttonMode = true;
publisher.y = yPos;
subitem.addChild(publisher);
trace("subsubbutton");
}
container.addChild(subitem);
trace("subbutton");
}
item.addChild(container);
addChild(item);
trace("button");
}
}
[/LEFT]