Simple workers/concurrency demo
Hi,
I would kindly ask if someone could give me a few pointers when it comes to using workers within the flash IDE (Mac, FP 14).
I have created a completely blank SWF called 'Worker.swf'.
I have also created another SWF called 'Main.swf'. The 'Main.swf' file only contains the following code (as pulled from Adobe documentation)...
import flash.system.Worker;
var bgWorker:Worker;
var workerLoader:URLLoader = new URLLoader();
workerLoader.dataFormat = URLLoaderDataFormat.BINARY;
workerLoader.addEventListener(Event.COMPLETE, loadComplete);
workerLoader.load(new URLRequest("Worker.swf"));
function loadComplete(event:Event):void {
var workerBytes:ByteArray = event.target.data as ByteArray;
bgWorker = WorkerDomain.current.createWorker(workerBytes);
bgWorker.addEventListener(Event.WORKER_STATE, workerStateHandler);
bgWorker.start();
function workerStateHandler(event:Event):void {
if (bgWorker.state == WorkerState.RUNNING) {
trace("The worker is running.");
}
}
}
I know this contains none of the callers etc, and if this is run in Debug, is compiles fine and the trace is successfully made.
HOWEVER
When I test this within the IDE (Test Movie), I get the following error:
| TypeError: Error #1009: Cannot access a property or method of a null object reference. at Main_fla::MainTimeline/loadComplete() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete() |
This error will be produced every time, unless the following lines are removed;
Code:
bgWorker.addEventListener(Event.WORKER_STATE, workerStateHandler);
bgWorker.start();
So, to me this appears to perhaps be an issue with the IDE itself, as opposed to the code? I would really be super appreciative if someone could provide their assistance.
My thanks in advance!!
