我正在尝试将图像获取和处理卸载到AIR / iOS应用中的Worker。但是,在调用loader.load()之后,加载器只会获得OPEN事件。此外,它会杀死任何Timers或Event.ENTER_FRAME监听,尽管Worker的状态显示为“正在运行”。
我的代码在Android设备(Galaxy S5)上的AIR模拟器和中按预期运行,但在iOS模拟器和设备本身都死了。以下是我的测试应用程序的每个AIR Sim,iOS Sim和iPhone的跟踪输出。您会注意到,对于iOS测试,它永远不会“完成”。我正在尝试同时加载4张图片,但也只是1:
AIR SIM Debug: (Works!) STARTING LOADER 0 STARTING LOADER 1 STARTING LOADER 2 STARTING LOADER 3 0 [Event type="open" bubbles=false cancelable=false eventPhase=2] 1 [Event type="open" bubbles=false cancelable=false eventPhase=2] 2 [Event type="open" bubbles=false cancelable=false eventPhase=2] 3 [Event type="open" bubbles=false cancelable=false eventPhase=2] [SWF] MultiLoaderWorkerTest.swf - 2,838 bytes after decompression [SWF] MultiLoaderWorkerTest.swf - 2,838 bytes after decompression 2 [Event type="complete" bubbles=false cancelable=false eventPhase=2] 0 [Event type="complete" bubbles=false cancelable=false eventPhase=2] 3 [Event type="complete" bubbles=false cancelable=false eventPhase=2] 1 [Event type="complete" bubbles=false cancelable=false eventPhase=2] iOS Simulator: (Broken!) [SWF] MultiLoaderWorkerTest.swf - 2,838 bytes after decompression [SWF] MultiLoaderWorkerTest.swf - 2,838 bytes after decompression STARTING LOADER 0 STARTING LOADER 1 STARTING LOADER 2 STARTING LOADER 3 0 [Event type="open" bubbles=false cancelable=false eventPhase=2] 1 [Event type="open" bubbles=false cancelable=false eventPhase=2] 2 [Event type="open" bubbles=false cancelable=false eventPhase=2] 3 [Event type="open" bubbles=false cancelable=false eventPhase=2] iOS Debug: (Broken!) [SWF] MultiLoaderWorkerTest.swf - 835 bytes after decompression [SWF] MultiLoaderWorkerTest.swf - 835 bytes after decompression STARTING LOADER 0 STARTING LOADER 1 STARTING LOADER 2 STARTING LOADER 3 0 [Event type="open" bubbles=false cancelable=false eventPhase=2] 1 [Event type="open" bubbles=false cancelable=false eventPhase=2] 2 [Event type="open" bubbles=false cancelable=false eventPhase=2] 3 [Event type="open" bubbles=false cancelable=false eventPhase=2] Android Debug: (Works!) [SWF] MultiLoaderWorkerTest.swf - 2,839 bytes after decompression [SWF] MultiLoaderWorkerTest.swf - 2,839 bytes after decompression STARTING LOADER 0 STARTING LOADER 1 STARTING LOADER 2 STARTING LOADER 3 1 [Event type="open" bubbles=false cancelable=false eventPhase=2] 0 [Event type="open" bubbles=false cancelable=false eventPhase=2] 2 [Event type="open" bubbles=false cancelable=false eventPhase=2] 3 [Event type="open" bubbles=false cancelable=false eventPhase=2] 3 [Event type="complete" bubbles=false cancelable=false eventPhase=2] 2 [Event type="complete" bubbles=false cancelable=false eventPhase=2] 1 [Event type="complete" bubbles=false cancelable=false eventPhase=2] 0 [Event type="complete" bubbles=false cancelable=false eventPhase=2]
我的代码如下。为了清晰起见,我删除了PROGESS和HTTP_STATUS事件,因为无论如何iOS测试都没有达到目标。
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLRequest;
import flash.system.MessageChannel;
import flash.system.Worker;
import flash.system.WorkerDomain;
public class MultiLoaderWorkerTest extends Sprite
{
private var worker:Worker
private var primordialToWorker:MessageChannel;
private var workerToPrimordial:MessageChannel;
private var loaders:Vector.<Loader>;
public function MultiLoaderWorkerTest()
{
if ( Worker.current.isPrimordial )
{
worker = WorkerDomain.current.createWorker( loaderInfo.bytes, true );
primordialToWorker = Worker.current.createMessageChannel( worker );
workerToPrimordial = worker.createMessageChannel( Worker.current );
worker.setSharedProperty( "primordialToWorker", primordialToWorker );
worker.setSharedProperty( "workerToPrimordial", workerToPrimordial );
workerToPrimordial.addEventListener( Event.CHANNEL_MESSAGE, onWorkerToPrimordial );
worker.start();
}
else
{
loaders = new Vector.<Loader>();
primordialToWorker = Worker.current.getSharedProperty( "primordialToWorker" );
workerToPrimordial = Worker.current.getSharedProperty( "workerToPrimordial" );
primordialToWorker.addEventListener( Event.CHANNEL_MESSAGE, onPrimordialToWorker );
workerToPrimordial.send( "READY" );
}
}
private function onWorkerToPrimordial( e:Event ) : void
{
var msg:* = workerToPrimordial.receive();
if ( msg == "READY" )
{
primordialToWorker.send( "GO" );
}
}
private function onPrimordialToWorker( e:Event ) : void
{
var msg:* = primordialToWorker.receive();
if ( msg == "GO" )
{
loadImage();
loadImage();
loadImage();
loadImage();
}
}
private function loadImage() : void
{
var loader:Loader = new Loader();
loaders.push( loader );
loader.contentLoaderInfo.addEventListener( Event.OPEN, traceEvent );
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, traceEvent );
loader.contentLoaderInfo.addEventListener( SecurityErrorEvent.SECURITY_ERROR, traceEvent );
loader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, traceEvent );
var req:URLRequest = new URLRequest( "http://www.thestar.com/content/dam/thestar/uploads/2014/6/26/1403815316554.jpg" );
trace( "STARTING LOADER", loaders.indexOf( loader ) );
loader.load( req );
}
private function traceEvent( e:Event ) : void
{
trace( loaders.indexOf( e.target.loader ), e.toString() );
}
}
}
非常感谢任何建议!