2007年9月16日星期日

load a pic with as 3

ActionScript3看起来更像一门程序设计语言了
//load a pic
var url0:String = "http://avatar.fanfou.com/l0/00/3f/v2.jpg?1188900628";
var url:String = " http://a1vatar.fanfou.com/l0/00/3f/v2.jpg?1188900628";


LoadPic(url);

function LoadPic(url:String):void {
    var requeste:URLRequest = new URLRequest(url);
    var loader:Loader = new Loader();
    configureListeners(loader.contentLoaderInfo);
    loader.load(requeste);
}

function configureListeners(dispatcher:IEventDispatcher):void {
    dispatcher.addEventListener (Event.COMPLETE, completeHandler);
    dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
function ioErrorHandler(event:IOErrorEvent):void {
    trace("ioErrorHandler: " + event);
    LoadPic(url0);
}
function completeHandler(event:Event):void {
    trace("completeHandler: " + event);
    addChild(event.target.content);
}

没有评论: