Question

For some reason, when I try to receive a shared property from a Worker (in AS3), the result is always null. That is, I send a value to a Worker using setSharedProperty(), when I retrieve it using getSharedProperty(), it always returns undefined/null.

Here's a simple test I set up:

package 
{
    import flash.display.Sprite;
    import flash.system.Worker;
    import flash.system.WorkerDomain;

    public class Main extends Sprite 
    {
        private var _worker:Worker;

        public function Main():void 
        {
            if (Worker.current.isPrimordial)
            {
                initMain();
            }
            else
            {
                initWorker();
            }
        }

        private function initMain():void 
        {
            _worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes);

            _worker.setSharedProperty("message", "test");
            _worker.start();
        }

        private function initWorker():void 
        {
            _worker = Worker.current;

            var message:String = _worker.getSharedProperty("message");

            trace(message);
        }

    }

}

When I trace message, the result is null. Although my main goal is to make an AIR app, I get the same result whether I'm compiling for AIR (3.7) or Flash Player (11.6, for some reason 11.7 doesn't recognise flash.system.Worker as a valid class).

I'm compiling using the Flex SDK, through FlashDevelop. Does anybody know what's wrong, maybe I've missed something in my code?

Was it helpful?

Solution

FlashDevelop now seems to have complete support for debugging workers which really wasn't the case on older versions (you could neither break, or trace inside workers). AIR SDK workers support has also progressed (I remember things working in release would break in debug version) I just recompiled your sample with AIR SDK 14 release (14.0.0.110)

air14_sdk_win/bin/mxmlc -swf-version=25 -debug=true Main.as

and debugged it with Shockwave Flash Debugger 14,0,0,125 and FlashDevelop 4.6.1.30 and got the expected result:

[Starting debug session with FDB]
Created Worker 2
test

Beware that any element not up-to-date in your debugging chain (sdk/player/debugger) could result in problems for debugging workers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top