Skip to main content
Šoški10369925
Participating Frequently
November 27, 2018
Question

Worker/MessageChannel testing/debugging in Flash CC IDE

  • November 27, 2018
  • 1 reply
  • 386 views

Hello,

when I'm trying to Test or Debug AIR app in Flash IDE that needs to communicate with Worker through MessageChannel, I don't receive any messages from Worker.

Can you tell me if I'm missing something or there's no way for MessageChannel to work without Publishing the app?

Here's the code that's in MainApp and Worker.

MainApp:

import flash.filesystem.File;

import flash.filesystem.FileStream;

import flash.utils.ByteArray;

import flash.system.Worker;

import flash.system.WorkerDomain;

import flash.system.MessageChannel;

import flash.events.Event;

var workerFile:File = File.applicationDirectory.resolvePath("TFR2.swf");

var fs:FileStream = new FileStream();

fs.open(workerFile, "read");

var workerBA:ByteArray = new ByteArray();

fs.readBytes(workerBA);

fs.close();

var worker:Worker = WorkerDomain.current.createWorker(workerBA, true);

var mainToWorker:MessageChannel;

var workerToMain:MessageChannel;

var workerToMainStartup:MessageChannel;

var mainToWorker:MessageChannel = Worker.current.createMessageChannel(worker);

worker.setSharedProperty("mainToWorker", mainToWorker);

var workerToMain:MessageChannel = worker.createMessageChannel(Worker.current);

workerToMain.addEventListener(Event.CHANNEL_MESSAGE, onWorkerToMain);

worker.setSharedProperty("workerToMain", workerToMain);

worker.start();

function onWorkerToMain(event:Event):void{

     trace(workerToMainStartup.receive());

}

Worker:

import flash.system.Worker;

import flash.system.MessageChannel;

if(!Worker.current.isPrimordial){

     var mainToWorker:MessageChannel = Worker.current.getSharedProperty("mainToWorker");

     mainToWorker.addEventListener(Event.CHANNEL_MESSAGE, onMainToWorker);

     var workerToMain:MessageChannel = Worker.current.getSharedProperty("workerToMain");

     workerToMainStartup.send("I'm ready to work!");

}

function onMainToWorker(event:Event):void{

     //process received data and return result

}

Thanks in advance.

This topic has been closed for replies.

1 reply

itlancer
Inspiring
November 29, 2018

I have the same problem.

Here the bug for that: Tracker