-
curiouser and curiouser
waiting for XML to load before continuing
hi there,
I've just started to sort out all my map data for my game into xml files - and I've run into trouble.
I've got the xml loading in, and the correct data is definitely being read - but I need the main code to wait until the XML is fully loaded before continuing.
What's the best way to do this so that no further instructions are run until the xml is fully loaded (without gotoAndStop-ing frames)?
many thanks for any help!
-
Code:
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad(success)
{
if(success)
{
// Your code here
}
}
myXML.load("mapData.xml");
Never give up...
-
curiouser and curiouser
thanks for the reply - that's pretty much what I've got, but it seems that any variables declared in the if(success) block don't exist out side of that - even though they're not declared using 'var'.
any ideas why that might be?
-
If you're about success variable -- it is local and returned by XML object when onLoad event is triggered.
You may start loading any XML file with that code and put a trace(this); command inside of "if" block to see that code is right
If you're about using other variables in that if statement block, declare them and they will be available as any other variables outside function's body (in a case with function...).
Sorry, english isn't my native so maybe I misunderstood you.
Never give up...
-
curiouser and curiouser
thanks again for replying - I've just been testing a few things and it seems that the numbers that I have in the xml file are being read in as strings - which was what was causing my problems.
I'm using EDMack's XML parsing function:
code: function processxml(thisxml) {
var thisobject = {map:[], npcs:[]};
_root.checkloaded = thisxml.firstChild.attributes.mname;
var thisxml = thisxml.firstChild.childNodes;
for (obj in thisxml) {
node = thisxml[obj];
if (node.nodeName == "row") {
thisobject.map.unshift(node.firstChild.nodeValue.s plit(","));
}
}
return thisobject;
}
what's the fastest way to ensure that any numbers in the XML file are read as numbers by flash?
thanks!
-
One thing that could be the problem is that you're trying to load too many things in one frame and Flash isn't parsing everything you need it to. Try putting your XML calls/global variables into it's own frame and maybe give your main timeline a few frames of leeway to make the connection before creating the XML.
Also a good practice is to put your XML functions all in one nice neat little AS file on its own, load it as an include in a preload frame, then add a second preload frame that calls the function.
Hopefully that helps.
-
I guess type cast will help you with strings to numbers convertion.
Never give up...
-
curiouser and curiouser
ok - thanks, I'll have to look into type casting
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|