2013-03-06 62 views
0

我在加载图片时遇到了swf文件错误。这里是我的代码:无法在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); 
    } 

e很不错,Google的标志出现了。但我需要操纵图像加载的像素。我添加一个图片位图:

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,并且没有错误或任何警告。 有人可以告诉我一个解决方案吗? 感谢您的阅读。

+0

您是否尝试添加其他处理程序,如IOErrorEvent或SecurityErrorEvent? – 2013-03-06 10:48:09

+0

确保类名和构造函数具有相同的名称('Battle')。你的代码绝对没有问题。 – 2013-03-06 10:54:26

+0

我想你使用普通的(不是调试)版本的Flash播放器。在调试播放器中,您将收到错误“SecurityError:Error#2122” – Smolniy 2013-03-06 13:10:14

回答

0

您不能访问像素数据的图像,如果图像是在不同的领域比你的应用程序(并没有crossdomain策略文件)

0

1你需要上的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); 

,但它只能如果谷歌添加跨域。

3您可以在您的域上使用小型serverside代理。 Flash呼叫代理获取文件与您的网址,代理下载并返回到闪存...