AS3加载文件时的异常捕获

So you want to load an image (jpg or something else like a swf) using AS3 ( actionscript 3 ) and then return the error ( or do something else like show a default image ) if the image doesn’t exist.
/*code*/
import flash.net.URLLoader;
import flash.display.Loader;
import flash.events.*;
var i = new Loader();
i.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
i.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);
i.load(new URLRequest(“http://www.kirupa.com/new_layout/modules/kirupaLogoGIF.gif”));
//change the url of the above line to something that doesn’t exist to test the error
movieClipInstance.addChild(i);
function errorHandler(event:ErrorEvent):void {
trace(“errorHandler: ” + event);
}
阅读(810) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
posted on 2016-01-25 16:33  玄冬  阅读(280)  评论(0编辑  收藏  举报