Solved

How do I catch lack of file

Posted on 2011-02-16
3
289 Views
Last Modified: 2012-05-11
What should I do to assign a function to the below xml-loading if the xml-file does not exist.
Some kind of if-statement or???
could it be
If( where != what)
var myXML:XML = new XML();
var XML_URL:String = "example.xml"
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myxmlLoader:URLLoader = new URLLoader(myXMLURL);
myxmlLoader.addEventListener("complete", xmlLoaded);

function xmlLoaded(event:Event):void
{
	myXML = XML(myxmlLoader.data);
}

Open in new window

0
Comment
Question by:petersego
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
edchipman earned 300 total points
ID: 34911028
You will want to listen for IOErrorEvent.IO_ERROR, when that event is dispatched you can handle things from there.
myxmlLoader.addEventListener("ioError", xmlLoadError);

function xmlLoadError(e:IOErrorEvent):void {
   //do something here
}

Open in new window

0
 
LVL 17

Assisted Solution

by:deepanjandas
deepanjandas earned 200 total points
ID: 34912924
On adding to @edchipman, also add a try and ctch to be on safer side that the file loading is in acceptable xml format. Like this one:
var myXML:XML = new XML();
var XML_URL:String = "example.xml"
var myxmlLoader:URLLoader = new URLLoader();
myxmlLoader.addEventListener("complete", xmlLoaded);
myxmlLoader.addEventListener("ioError", xmlLoadError);


function xmlLoaded(event:Event):void
{
        myXML = XML(myxmlLoader.data);
}

function xmlLoadError(e:IOErrorEvent):void {
   //do something here
}

try{
     myxmlLoader.load( myXMLURL );
}catch( e:Error){
     trace(e);
}

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Closing Comment

by:petersego
ID: 34916101
Thank you both.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question