0

我正在创建一个 Flash 引擎,并且我有一个 Loader 类。当我在地图中打开 .swf 文件时它可以工作,但是当我在我的服务器上打开它时它不会。HTTP 状态返回 200,因此这意味着它有连接但图像不显示...这是如何引起的,我该如何解决?

package com.loading{
import flash.display.Loader;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.EventDispatcher;
import com.events.LoaderEvent;
import flash.media.SoundChannel;
import flash.events.HTTPStatusEvent;

public class Loader extends EventDispatcher {

    public var returnImages:Array = new Array();

    public var totalImages:int = 0;

    public function Loader() {
    }

    public function LoadImage(path:String) {
        var imgLoader:flash.display.Loader = new flash.display.Loader();
        imgLoader.contentLoaderInfo.addEventListener(LoaderEvent.COMPLETE, loadImageComplete);
        imgLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpError,false,0,true);
        imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, error, false, 0 ,true);
        imgLoader.load(new URLRequest(path));
        totalImages = 1;
    }

    public function LoadImages(paths:Vector.<String>) {
        totalImages = paths.length;
        for (var i:int = 0; i<paths.length; i++) {
            var imgLoader:flash.display.Loader = new flash.display.Loader();
            imgLoader.contentLoaderInfo.addEventListener(LoaderEvent.COMPLETE, loadImageComplete);
            imgLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpError,false,0,true);
            imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, error, false, 0 ,true);
            imgLoader.load(new URLRequest(paths[i]));
        }
    }

    private function loadImageComplete(e:Event) {
        returnImages.push(e.target.content);
        if (returnImages.length == totalImages) {
            dispatchEvent(new LoaderEvent(LoaderEvent.ALL_IMAGES_LOADED,0,totalImages,true));
        } else {
            dispatchEvent(new LoaderEvent(LoaderEvent.IMAGE_LOADED,returnImages.length,totalImages,true));
        }
    }

    private function error(e:IOErrorEvent) {
        dispatchEvent(new LoaderEvent(LoaderEvent.ERROR,0,0,e.text,true));
    }

    private function httpError(e:HTTPStatusEvent) {
        if (e.status != 200) {
            dispatchEvent(new LoaderEvent(LoaderEvent.ERROR,0,0,e.status,true));
        }
    }



}

}

这就是它的加载方式:

var lo:com.loading.Loader = new com.loading.Loader();
lo.LoadImage("http://s3files.core77.com/blog/images/Balloon-Tank.jpg");
lo.addEventListener(LoaderEvent.ERROR, error, false, 0 ,true);
lo.addEventListener(LoaderEvent.ALL_IMAGES_LOADED,loadImage, false, 0, true);
function loadImage(e:LoaderEvent) {
for (var i:int =0; i<e.totalPosition; i++) {
    info.appendText("Loaded Image: " + i+"\n");
    try {
        var tempBitmap:Bitmap = lo.returnImages[i];
        tempBitmap.scaleX = tempBitmap.scaleY = 2;
        tempBitmap.alpha = 0.5;
        addChild(tempBitmap);
    } catch (error:Error) {
        info.appendText("Catched Error: " + error.toString() + "\n");
    }
}
}

function error(e:LoaderEvent) {
info.appendText("Error: " + e.currentString+"\n");
}
4

1 回答 1

1

Bitmap我认为当您从加载的图像创建新图像并尝试操作其scalealpha属性时,您会遇到跨域问题。快速解决方法是从托管 SWF 的同一服务器加载测试图像。

如果您对与 Flash 相关的跨域策略感兴趣,您应该阅读(相当深奥的)Adobe 文档,特别是标题为“遍历显示列表”的部分。

于 2012-07-30T23:34:26.973 回答