# Names from extenal XML file to string variable

**URL:** https://forum.kirupa.com/t/names-from-extenal-xml-file-to-string-variable/266343
**Category:** flash
**Created:** [July 18, 2008, 4:14pm UTC](https://forum.kirupa.com/t/names-from-extenal-xml-file-to-string-variable/266343 "2008-07-18T16:14:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![boris28](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@boris28](https://forum.kirupa.com/u/boris28)
#### Post date: [July 18, 2008, 4:14pm UTC](https://forum.kirupa.com/t/names-from-extenal-xml-file-to-string-variable/266343/1 "2008-07-18T16:14:59Z")

</div>

I’m new to AS 3 and I have this problem:  
I want to make a dynamic menu with some buttons. Names(labels) of these buttons are in external XML file. Parameters of buttons are specified in main file .fla. I have also actionscript file .as (it works without errors), which makes these buttons with parameters specified in main file .fla .And I want to GET NAMES OF BUTTONS FROM EXTERNAL XML FILE TO STRING VARIABLE, but here is the problem. How could I do that? Please help.

## Here are my scripts:

this is in main file .fla:

import flash.events._;  
import [flash.net](http://flash.net)._;  
import flash.text.\*;

//declarations  
var NumberofButtons:Number = 3;  
var xposition:Number=25;  
var textBut:String=new String;

//load XML file names.xml  
var navData:XML;  
var loader:URLLoader = new URLLoader();  
loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);  
loader.addEventListener(IOErrorEvent.IO\_ERROR, onIOError, false, 0, true);  
loader.load(new URLRequest(“names.xml”));

function onComplete(evt:Event):void {  
try {  
navData = new XML(evt.target.data);  
trace(navData);  
loader.removeEventListener(Event.COMPLETE, onComplete);  
loader.removeEventListener(IOErrorEvent.IO\_ERROR, onIOError);  
} catch (err:Error) {  
trace("Could not parse loaded content as XML:  
" + err.message);  
}  
}  
function onIOError(evt:IOErrorEvent):void {  
trace ("An error occured when attempting to load the XML " + err.message);  
}

## //parameters of buttons for (var i:Number=0; i\<NumberofButtons; i++) { //text of button label - [COLOR=“Red”]HERE IS PROBLEM MAYBE[/COLOR] [COLOR="#ff0000"]textBut= navData.buttons.button\*.text();[/COLOR] function positions():Number { xposition=xposition+75; return xposition; } // CreationBtn(hightofButton, widthofButton, colorofButton, colorofTextLabel, // textLabelofButton, xpositionofButton) var btn:Sprite = new CreationBtn(25,50,0xFFFF00,0x000000,textBut,positions()); addChild(btn); }

## here is XML file - names.xml \<buttons\> \<button\>Animations\</button\> \<button\>Photo\</button\> \<button\>Books\</button\> \</buttons\>

## actionscript file is CreationBtn.as and has no errors
