Solved

How do I catch lack of file

Posted on 2011-02-16
3
286 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
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 how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

738 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