Skip to main content
Participating Frequently
January 13, 2017
Question

Worker not functionning in distribution or TestFlight build

  • January 13, 2017
  • 1 reply
  • 356 views

I'm using an embedded SWF file to use as a worker in my app. On iOS devices, the communication with the worker is fine when I debug the app. Builds created for TestFlight (distribution build), won't function properly. I can trace the state of the worker as "running" but nothing is comming through the messageChannels.

// embed SWF

[Embed(source="../../workers/WorkerTest.swf", mimeType="application/octet-stream")]

private static var WORKER_SWF:Class;

protected var worker:Worker;

private var workerToMainStartupChannel:MessageChannel;

// Create the worker

var workerBytes:ByteArray = new SOUNDWAVE_SWF() as ByteArray;

worker = WorkerDomain.current.createWorker(workerBytes);

// set up channel

workerToMainStartupChannel = worker.createMessageChannel(Worker.current);

workerToMainStartupChannel.addEventListener(Event.CHANNEL_MESSAGE, onWorkerToMainStartup);

worker.setSharedProperty("workerToMainStartup", workerToMainStartupChannel);

worker.addEventListener(Event.WORKER_STATE,onWorkerState);

worker.start();

private function onWorkerState(e:Event):void

{

  if (worker.state == WorkerState.RUNNING)

  {

     // this always gets traced

    trace("WORKER RUNNING");

    }

}

public function onWorkerToMainStartup(evt:Event):void

{

     // this only gets traced on debug builds

  var success:Boolean = workerToMainStartupChannel.receive() as Boolean;

  if (!success)

  {

  trace("worker failure")

  }

  else

  {

  trace("worker stared");

  }

  }

}

// WORKER

public class WorkerTest extends Sprite

{

  protected var workerToMainStartup:MessageChannel;

  public function WorkerTest()

  {

  // Send startup message to main

  workerToMainStartup = Worker.current.getSharedProperty("workerToMainStartup");

  workerToMainStartup.send(true);

  }

}

Note : the Worker SWF is published to a folder inside the the main app structure.

Any ideas?

Cheers

This topic has been closed for replies.

1 reply

Participating Frequently
February 17, 2017

I found the answer. The SWF must be loaded and not Embeded, like so :

loader = new Loader();

lc = new LoaderContext(false,ApplicationDomain.currentDomain,null);

file = File.applicationDirectory.resolvePath("workers/TestWorker.swf");

loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, onLoadedHandler);

// on loaded

protected function onWorkerLoadedHandler(evt:Event):void

{

     worker = WorkerDomain.current.createWorker(evt.target.bytes,true);

     // set up message channels and shared props

}