Solved

How do I catch lack of file

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Streaming to Flash Media Server with ffmpeg, crashes on start 3 247
Error 2032 in all the browser 6 2,837
System Center Configuration Manager 2012R2 7 86
PDF: Display my cards game? 8 110
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

772 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