PDA

View Full Version : Loaded XML data as a root variable - inside a movieclip?



smriyaz
April 25th, 2008, 04:26 PM
Hi,
I'm trying to do a message viewer animation which will get some sample messages from a xml an load the data in a root variable. I've created the animation in separate movieclip which is having a textfield inside to hold the messages. when I try to load the data and trace it in the root it's working perfectly. but if I call this root variable inside the particular movieclip, it's not loading and even not tracing the root variable. can anybody help me how to do this? I've checked with the xml loading it's working (otherwise it won't trace in the root I hope) and I tried creating a dummy variable outside the function and called inside the movieclip and it's also working. I hope somebody with guide me in this. Thanks in advance.

The root code


var testVar:String = "This is a test text"; // if I call this variable inside the movieclip it works

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("msg.xml"));

function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);

ParseMsg(xmlData);

}
function ParseMsg(msgInput:XML):void {

var msgListGroup:XMLList = msgInput.cat.(@ID == id).m;

trace (msgListGroup); // this trace works and print the messages stored in the xml

}
This is the code I'm using inside the movieclip


trace(MovieClip(root).msgListGroup); // this is where I refer the root variable but it traces 'undefine'
trace(MovieClip(root).testVar); // this one traces well (the dummy variable)

magcius
April 25th, 2008, 05:05 PM
You defined the msgListGroup inside the function. If you move the declaration (not the assignment) up at the top, it should work. If you tried to trace msgListGroup outside the function on the frame it wouldn't work either.

smriyaz
April 27th, 2008, 02:20 AM
Thanks magcius, However I got the same replies from some other forums and it works now. I should define it outside the function. thanks a lot.
Regards.