PDA

View Full Version : VAR in MC from XML


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.

Sekhar
11-11-2008, 04:05 AM
Well, mc is a local variable whose value changes as you iterate and stays with the last one assigned. For the event handler to access the clip that generated the event, instead of mc.myHeading, use event.currentTarget.myHeading.

r3tic
11-11-2008, 01:16 PM
Works like a charm....Thanks