r3tic
11-10-2008, 11:53 PM
I am trying to load a var into a mc from xml and I am having some problems. My code is as follows...
flash.events.MouseEvent;
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, processXML);
var myXML:XML;
function processXML(e:Event):void {
myXML=new XML(e.target.data);
for (var i:int = 0; i<myXML.*.length(); i++) {
var mc:btnTemp=new btnTemp();
this.addChild(mc);
mc.y=50;
mc.x=(i* 120)+50;
mc.btnText.text=myXML.*[i].@text;
mc.myHeading=(myXML.*[i].desc);
//trace(mc.myHeading);
mc.myContent=myXML.*[i].Content;
//trace(mc.myContent);
mc.addEventListener (MouseEvent.MOUSE_UP,buttonPressed);
function buttonPressed(event:MouseEvent) {
//trace(mc.myHeading);
//trace(mc.myContent);
txtHeading.text=mc.myHeading;
txtContent.text=mc.myContent;
}
}
}
myLoader.load(new URLRequest("navigation.xml"));
I have three instances of a mc that act as buttons. The text for the buttons(mc) as well as heading and content comes from the XML file. the first two trace() generate the correct information indication that the information is being transfered properly to the mc instances. However, the second two times I trace(), I am only getting the heading and content for the last mc generated, reguardless of which one I click on.
Any help would be greatly appreciated.
flash.events.MouseEvent;
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, processXML);
var myXML:XML;
function processXML(e:Event):void {
myXML=new XML(e.target.data);
for (var i:int = 0; i<myXML.*.length(); i++) {
var mc:btnTemp=new btnTemp();
this.addChild(mc);
mc.y=50;
mc.x=(i* 120)+50;
mc.btnText.text=myXML.*[i].@text;
mc.myHeading=(myXML.*[i].desc);
//trace(mc.myHeading);
mc.myContent=myXML.*[i].Content;
//trace(mc.myContent);
mc.addEventListener (MouseEvent.MOUSE_UP,buttonPressed);
function buttonPressed(event:MouseEvent) {
//trace(mc.myHeading);
//trace(mc.myContent);
txtHeading.text=mc.myHeading;
txtContent.text=mc.myContent;
}
}
}
myLoader.load(new URLRequest("navigation.xml"));
I have three instances of a mc that act as buttons. The text for the buttons(mc) as well as heading and content comes from the XML file. the first two trace() generate the correct information indication that the information is being transfered properly to the mc instances. However, the second two times I trace(), I am only getting the heading and content for the last mc generated, reguardless of which one I click on.
Any help would be greatly appreciated.