无法在swf中加载图像

时间:2013-03-06 10:45:47

标签: actionscript-3 bitmap loader

我在加载图像到swf文件时出错。这是我的代码:

    private var loader:Loader = new Loader(  );
    public function Battle()
    {
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
        loader.load(new URLRequest("http://www.google.com.vn/images/srpr/logo4w.png"));
    }
    private function onComplete(event:Event):void
    {

        addChild(loader);
     }
很可爱,谷歌的标志出现了。但我需要操纵图像加载的像素。我添加了一个图像Bitmap:

    private var loader:Loader = new Loader(  );
    private var image:Bitmap;

    public function Battle()
    {
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
        loader.load(new URLRequest("http://www.google.com.vn/images/srpr/logo4w.png"));
    }
    private function onComplete(event:Event):void
    {

        image =  Bitmap(loader.content);
        this.addChild(image);

    }

没有任何东西出现。我在互联网上找不到任何解决方案。我试着发现:

private function onComplete(event:Event):void
    {

        image =  Bitmap(loader.content);
        //after above line, rest of function never run
        addChild(image);   // <-- no run @@
        trace("this no run"); // <-- no run @@
    }

我使用Flash Builder 4并且没有错误或任何警告。 有人可以给我一个解决方案吗? 感谢阅读。

2 个答案:

答案 0 :(得分:0)

如果图片与您的应用程序位于不同的域中(并且没有crossdomain策略文件),则无法访问图像的像素数据

答案 1 :(得分:0)

1您需要在Google网站上使用crossdomain.xml:)

2您需要使用checkpolicy:

var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("http://www.google.com.vn/images/srpr/logo4w.png"), context);

但仅当Google添加跨域时才有效。

3您可以在您的域上使用小型服务器端代理。 Flash调用代理用你的url获取文件,代理下载并返回flash ...