Solved

How do I catch lack of file

Posted on 2011-02-16
3
250 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
3 Comments
 
LVL 5

Accepted Solution

by:
edchipman earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you both.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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. …
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now