urlstream

来源:互联网 发布:知乎著名哲学思想 编辑:程序博客网 时间:2024/05/16 04:43

var stream:URLStream=new URLStream();
var imgdata:ByteArray=new ByteArray();
var loader:Loader=new Loader();

btn2.addEventListener(MouseEvent.CLICK,loadfun);
function loadfun(e:MouseEvent):void {
    stream.load(new URLRequest("img/p2.jpg"));
}

stream.load(new URLRequest("img/p1.jpg"));

//加载完成后 触发
stream.addEventListener(Event.COMPLETE,completefun);
//加载中 触发
stream.addEventListener(ProgressEvent.PROGRESS,progressfun);
//加载中 执行
function progressfun(e:ProgressEvent):void {
    trace("~~~");
}
//完成后 执行
function completefun(e:Event):void {
    // 将 stream(URLStream对象)的字节数指定到imgdata(ByteArray对象)中
    stream.readBytes(imgdata);
    // 判断 URLStream 对象目前是否已连接
    if (stream.connected) {
        //立即关闭该流并取消下载操作
        stream.close();
    }
    //删除此 Loader 对象中使用 load() 方法加载的子项
    loader.unload();
    //加载loader(ByteArray 对象)中所存储的二进制数据
    loader.loadBytes(imgdata);
    addChild(loader);
}

function connectfun(e:ProgressEvent):void {
    trace(stream.connected);
}

原创粉丝点击