2

I am trying to load swf from an url. there isnt an error but i am trying to give error if internet connection was lost. I used this code. it loads the url but not give an error.where is my mistake can you help me?

var myLoader:Loader = new Loader();  

try {
    var url:URLRequest = new URLRequest("http://....swf");
    myLoader.load(url);                                  
    addChild(myLoader); 
} 
catch(error:Error){ 
    trace("Error loading image thumbnail");
}

1 Answers1

3

try-catch doesn't work for loading resources. As loading a resource is an asynchronous process the error is not thrown immediately, so try-catch is not able to catch the error. In this case, error handling is done using event listeners as show below:

var myLoader:Loader = new Loader();  
myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);  

var url:URLRequest = new URLRequest("http://....swf");
myLoader.load(url);                                  
addChild(myLoader); 

function loaderIOErrorHandler(e:Event){
    trace("Error loading image thumbnail");
}
shinobi
  • 2,511
  • 1
  • 19
  • 27