我在加载图片时遇到了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,并且没有错误或任何警告。 有人可以告诉我一个解决方案吗? 感谢您的阅读。
您是否尝试添加其他处理程序,如IOErrorEvent或SecurityErrorEvent? – 2013-03-06 10:48:09
确保类名和构造函数具有相同的名称('Battle')。你的代码绝对没有问题。 – 2013-03-06 10:54:26
我想你使用普通的(不是调试)版本的Flash播放器。在调试播放器中,您将收到错误“SecurityError:Error#2122” – Smolniy 2013-03-06 13:10:14