ActionScript 3:LoaderInfo COMPLETE 事件在 load() 和 loadBytes() 之后不会触发
我正在尝试使用带有 Loader 对象的 ActionScript 加载 PNG 图像。这对于某些图像效果很好(INIT 和 COMPLETE 事件按预期触发),而对于其他图像则不然。我在这个帖子中读到 URLLoader 可能会有所帮助,所以我尝试了,之后使用 loadBytes() 函数。仍然不起作用:URLLoader 触发 COMPLETE 事件,但 LoaderInfo 对象不会。
我编写了一个示例类,它演示了两个文件的问题(一个有效,另一个无效)。
public class LoaderTest extends MovieClip {
var output:TextField;
var loader:Loader;
var urlLoader:URLLoader;
function LoaderTest() {
output = new TextField();
output.width = 1000;
output.height = 1000;
output.multiline = true;
addChild(output);
var t1:Timer = new Timer(0, 0);
t1.addEventListener(TimerEvent.TIMER, function() {
t1.stop(); loadMapDirect("map_in_big.png");
});
var t2:Timer = new Timer(1000, 0);
t2.addEventListener(TimerEvent.TIMER, function() {
t2.stop(); loadMapDirect("map_us_big.png");
});
var t3:Timer = new Timer(2000, 0);
t3.addEventListener(TimerEvent.TIMER, function() {
t3.stop(); loadMapBytes("map_in_big.png");
});
var t4:Timer = new Timer(3000, 0);
t4.addEventListener(TimerEvent.TIMER, function() {
t4.stop(); loadMapBytes("map_us_big.png");
});
t1.start();
t2.start();
t3.start();
t4.start();
}
function loadMapBytes(url:String):void {
try {
urlLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(ProgressEvent.PROGRESS, progressListener);
urlLoader.addEventListener(Event.COMPLETE, completeListenerBytes);
output.appendText("\nLoading '"+url+"' with URLLoader ");
urlLoader.load(new URLRequest(url));
} catch (error:Error) {
output.appendText("Err: " + error.message + "\n");
}
}
function completeListenerBytes(e:Event):void {
output.appendText("COMPLETE Event fired for URLLoader!\n");
try {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListenerDirect);
output.appendText("Loading bytes with Loader ");
loader.loadBytes(e.target.data as ByteArray);
} catch (error:Error) {
output.appendText("Err: " + error.message + "\n");
}
}
function loadMapDirect(url:String):void {
try {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListenerDirect);
output.appendText("\nLoading '"+url+"' with Loader ");
loader.load(new URLRequest(url));
} catch (error:Error) {
output.appendText("Err: " + error.message + "\n");
}
}
function completeListenerDirect(e:Event):void {
var bmd:BitmapData = Bitmap(e.target.loader.content).bitmapData;
output.appendText("COMPLETE Event fired for Loader! => h: " + bmd.height + ", w: " + bmd.width + "\n");
}
function progressListener (e:ProgressEvent):void{
output.appendText(".");
if (e.bytesLoaded == e.bytesTotal) {
output.appendText(" progress complete, " + e.bytesTotal + " bytes loaded!\n");
}
}
}
所有图像都是使用 PHP GD 库生成的,我使用 SWFTools 的 as3compile 进行编译。
您可以在 http://www.wichte-sind 上查看脚本的运行情况-wichtig.de/as3loader/loaderTest.swf
两张图片map_in_big.png和map_us_big.png在同一个文件夹中(不允许发布更多超链接)。
有什么想法吗?
I'm trying to load PNG images with ActionScript with a Loader object. This works fine for some of the images (the INIT and COMPLETE events are fired as expected), for some other it doesn't. I've read in this thread that a URLLoader might help, so I tried that, using the loadBytes() function afterwards. Still doesn't work: the URLLoader fires the COMPLETE event, but the LoaderInfo object does not.
I've written a sample class that demonstrates the problem with two files (one working, the other one not).
public class LoaderTest extends MovieClip {
var output:TextField;
var loader:Loader;
var urlLoader:URLLoader;
function LoaderTest() {
output = new TextField();
output.width = 1000;
output.height = 1000;
output.multiline = true;
addChild(output);
var t1:Timer = new Timer(0, 0);
t1.addEventListener(TimerEvent.TIMER, function() {
t1.stop(); loadMapDirect("map_in_big.png");
});
var t2:Timer = new Timer(1000, 0);
t2.addEventListener(TimerEvent.TIMER, function() {
t2.stop(); loadMapDirect("map_us_big.png");
});
var t3:Timer = new Timer(2000, 0);
t3.addEventListener(TimerEvent.TIMER, function() {
t3.stop(); loadMapBytes("map_in_big.png");
});
var t4:Timer = new Timer(3000, 0);
t4.addEventListener(TimerEvent.TIMER, function() {
t4.stop(); loadMapBytes("map_us_big.png");
});
t1.start();
t2.start();
t3.start();
t4.start();
}
function loadMapBytes(url:String):void {
try {
urlLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(ProgressEvent.PROGRESS, progressListener);
urlLoader.addEventListener(Event.COMPLETE, completeListenerBytes);
output.appendText("\nLoading '"+url+"' with URLLoader ");
urlLoader.load(new URLRequest(url));
} catch (error:Error) {
output.appendText("Err: " + error.message + "\n");
}
}
function completeListenerBytes(e:Event):void {
output.appendText("COMPLETE Event fired for URLLoader!\n");
try {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListenerDirect);
output.appendText("Loading bytes with Loader ");
loader.loadBytes(e.target.data as ByteArray);
} catch (error:Error) {
output.appendText("Err: " + error.message + "\n");
}
}
function loadMapDirect(url:String):void {
try {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListenerDirect);
output.appendText("\nLoading '"+url+"' with Loader ");
loader.load(new URLRequest(url));
} catch (error:Error) {
output.appendText("Err: " + error.message + "\n");
}
}
function completeListenerDirect(e:Event):void {
var bmd:BitmapData = Bitmap(e.target.loader.content).bitmapData;
output.appendText("COMPLETE Event fired for Loader! => h: " + bmd.height + ", w: " + bmd.width + "\n");
}
function progressListener (e:ProgressEvent):void{
output.appendText(".");
if (e.bytesLoaded == e.bytesTotal) {
output.appendText(" progress complete, " + e.bytesTotal + " bytes loaded!\n");
}
}
}
All images were generated with the PHP GD library and I'm compiling with SWFTools's as3compile.
You can see the script it in action on http://www.wichte-sind-wichtig.de/as3loader/loaderTest.swf
The two images map_in_big.png and map_us_big.png are in the same folder (not allowed to post more hyperlinks).
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您的应用程序可能是为 Flash Player 9 编译的。在版本 9 中,允许的最大图像尺寸为 2880 x 2800,map_us_big.png 为 3150 x 1570。当我为 Flash Player 10 编译该应用程序时,我成功运行了该应用程序。
以下是参考文献http://help.adobe .com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#BitmapData%28%29
The problem is that your application is probably compiled for Flash Player 9. In version 9 the maximum allowed image dimensions are 2880 x 2800 and map_us_big.png is 3150 x 1570. I ran the application successfully when I compiled it for Flash Player 10.
Here's a reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#BitmapData%28%29