create dynamic navigation from xml file in flash cs3

Posted by mjr on Stack Overflow See other posts from Stack Overflow or by mjr
Published on 2009-04-30T13:22:32Z Indexed on 2011/03/11 0:10 UTC
Read the original article Hit count: 179

Filed under:

action script newbie here :-)

What I want to do is this, hand an xml file to a swf and have the swf generate a dynamic text box and button for each of the links in the xml file

a rudimentary navigation

here's the xml

<?xml version="1.0" encoding="UTF-8"?>
    <page name="Page Name 1" url="/page-1/" />
    <page name="Page Name 2" url="/page-2/" />
    <page name="Page Name 3" url="/page-3/" />
    <page name="Page Name 4" url="/page-4/" />

and in my fla I have a button in my library named 'nav_button'

there's a layer named actions and in frame 1 I have this

var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();

var button:Button = new Button();

xmlLoader.load(new URLRequest("links.xml"));

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
xml = XML(;
xmlList = xml.children();

for(var i:int = 0; i < xmlList.length(); i++)
	button = new Button();
	button.x = 25;
	button.y = i * 50 +25; 

the xml imports fine, but when it comes to the for loop and adding the buttons and text boxes to the stage, I'm toast

© Stack Overflow or respective owner

Related posts about Xml

Related posts about flash