PDA

Click to See Complete Forum and Search --> : error handling



kdickinson
07-08-2001, 09:41 AM
I need to create a handler that will detect whether an XML file exists or not. I've tried loading the non-existent file and Flash generates the usual error in the output window. When running as a stand-alone or in a browser, the error message doesn't appear so I don't have to worry about that when running the final app. The trick is, I can't find any actionscript to determine whether or not the file has loaded. Any ideas?

kdickinson

VAYKENT
07-08-2001, 10:09 PM
So you can use the 'loaded', 'onLoad', and 'status' methods of the XML object....

nameOfXMLObj = new XML;
nameOfXMLObj.onLoad = dealWithIt;
nameOfXMLObj.load("yourXML.xml");

function dealWithIt(success){
if(success){
possibleErrors = nameOfXMLObj.status
if(possibleErrors==0){
trace("XML document was loaded successfully with no errors.");
}else{
trace("XML document was loaded returning the error code: "+possibleErrors);
}
}else{
trace("XML document was not loaded successfully.");
}
}

The 'loaded' property can be used in much the same way, but inside some loop. nameOfXMLObj.loaded will return true when the document was loaded... (duh!) - but the same as onLoad - it will not tell you if it was loaded successfully (without errors).

kdickinson
07-08-2001, 11:05 PM
Thanks for the help. Actually the status still doesn't do what I want (amazingly enough) but you did give me the answer. For the record, here's what works:

test = new XML();
test.onLoad = testload;
test.load("somexml.xml");

function testload(bSuccess){
if (!bSuccess){
trace ("success says it didn't load"); // even thought the file isn't there, bSuccess returns true.
}
possibleErrors = _root.test.status
if(possibleErrors==0){
trace("XML document was loaded successfully with no errors."); // even with no file, possible errors == 0
}else{
trace("XML document was loaded returning the error code: "+possibleErrors); // only goes off when a file is actually in place
}
if (this.loaded){ // yep, this one works even within the load handler (no loop needed). I tried it both ways (file and no file).
trace ("even loaded says it's loaded");
}else{
trace ("finally, an error");
}
}

Once again, thanks. I didn't think the loaded property would do it but is does.

Ken