In the last line, I want the XML function to read the name of the button clicked and show the corresponding tag in the XML file (the tags in the XML file has the same names of the buttons), or instead I will have to make functions or if statements equal to the number of buttons I have! this does not make any sense to me!
stop();
import flash.events.MouseEvent;
import flash.events.Event;
import flash.net.URLLoader;
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
var myVar:String = new String();
//var myFrame:Array=new Array(26);
var words:Array =['Amon','Ahmos','Ramsis'];//the words
for (var j:int=0; j<words.length; j++)
{
var word:MovieClip = CreatTextButton(words[j]);//loop in myDictionary and name each button with a different name
addChild(word);
word.x = 130;
word.y = 16 + (j * 30);// to change the position of each word
word.addEventListener(MouseEvent.CLICK,onWordClick);
function CreatTextButton(label:String):MovieClip //creat buttons
{
var txt:TextField = new TextField();
txt.defaultTextFormat = new TextFormat('Calibri',20,0x000000);
txt.text = label;
txt.autoSize = TextFieldAutoSize.LEFT;
txt.background = txt.border = true;
txt.selectable = false;
var btn:MovieClip = new MovieClip();
btn.label=label;
btn.mouseChildren = false;
btn.addChild(txt);
btn.buttonMode = true;
myVar=label.valueOf();
trace(myVar);
return btn;
}
function onWordClick(event:MouseEvent)
{
var myLoader:URLLoader= new URLLoader();
myLoader.load(new URLRequest("1.xml"));
myLoader.addEventListener(Event.COMPLETE,loadXML);
var label:String = event.currentTarget.label;
trace(label);
}
function loadXML(e:Event)
{
var myxml:XML = new XML(e.target.data);
mydata.text += String(myxml.label)+"\n";
}
}
my XML is
<Pharaohs>
<Ahmos id='_1'>
reigned c. 1539–14 bce and founder of the 18th dynasty
</Ahmos>
<Amon id='_2'>
The chief deity of the Egyptian Empire
</Amon>
<Ramsis id='_3'>
The third Pharaoh of the 19th dynasty
</Ramsis>
</Pharaohs>
Sorry for being so slow and stupid :D