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.;
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);
}