Skip navigation
ian10037
Currently Being Moderated

Is it possible to use workers if one develops in the Flash IDE?

Jun 23, 2013 4:12 AM

Tags: #action_script_3 #concurrency #workers #flash_ide

I've been tryting to get the new concurrency feature working - I downloaded Flash CC and have the latest versions (11.7) of the player and plug-ins installed. But - none of the code from the forums or AS3 reference works (and yes, I've tweaked it so it compiles either as an external as class or as timeline code).

 

There are no errors, but Worker.isSupported returns false.

 

I'm a very confident coder (usually), but this has me completely stumped....

 
Replies
  • Currently Being Moderated
    Jun 25, 2013 3:18 AM   in reply to ian10037

    Yes. You should be able to use workers. Workers can only be used for background processing. There are mechanisms for communication with workers using shared properties and channels.

    Check the url below.

     

    http://help.adobe.com/en_US/as3/dev/WS2f73111e7a180bd0-5856a8af1390d64 d08c-7ffe.html

     

    I am also sharing a simple sample which shows usage of worker.

     

    Loader movie which is loading the worker (LoaderMovie.swf)

     

    package  {

     

              import flash.display.MovieClip;

              import flash.net.*;

              import flash.events.*;

              import flash.concurrent.*;

              import flash.utils.ByteArray;

              import flash.system.Worker;

              import flash.system.*;

              import flash.events.Event;

     

     

              public class LoaderMovie extends MovieClip {

     

                        private var worker:Worker;

     

                        public function LoaderMovie() {

                                  // constructor code

     

     

                                  //Load the swf for worker

                                  var workerLoader:URLLoader = new URLLoader();

                                  workerLoader.dataFormat = URLLoaderDataFormat.BINARY;

                                  workerLoader.addEventListener(Event.COMPLETE, loadComplete);

                                  workerLoader.load(new URLRequest("simpletween.swf"));

                                  this.addEventListener(Event.ENTER_FRAME, handleEnterFrame);

     

                        }

     

                        public function loadComplete(evt:Event):void

                        {

                                  var workerBytes:ByteArray = evt.target.data as ByteArray;

                                  worker = WorkerDomain.current.createWorker(workerBytes);

                                  worker.addEventListener(Event.WORKER_STATE, workerStateHandler);

                                  worker.setSharedProperty("counter", 10);

                                  worker.start();

                                  this.play();

                        }

     

                        public function workerStateHandler(evt:Event)

                        {

                                  if(worker.state == WorkerState.RUNNING)

                                  {

                                            this.WorkerStateText.text = "Worker Running";

     

                                  }

                                  else if (worker.state == WorkerState.NEW)

                                  {

                                            this.WorkerStateText.text = "Worker created";

     

                                  }

                        }

     

                        public function handleEnterFrame(evt:Event)

                        {

                                  if(worker)

                                  {

                                            this.WorkerCounter.text = worker.getSharedProperty("counter");

                                  }

                        }

              }

     

    }

     

    The worker movie clip (simpletween.swf)

     

    package  {

     

              import flash.display.MovieClip;

              import flash.net.*;

              import flash.events.*;

              import flash.system.*;

     

     

              public class simpleTween extends MovieClip {

     

     

                        public function simpleTween() {

                                  // constructor code

                                  this.play();

                                  this.addEventListener(Event.ENTER_FRAME, handleEnterFrame);

     

                        }

     

                        public function handleEnterFrame(evt:Event)

                        {

                                  var counter:int = Worker.current.getSharedProperty("counter");

                                  counter = counter + 10;

                                  Worker.current.setSharedProperty("counter", counter);

                        }

              }

    }

     

    Hope this helps

     

    Vinod

    Engineer

    Flash Pro CC

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2013 10:27 PM   in reply to ian10037

    Hi Ian

     

    It has been tested in Flash CC and hence should work. In fact, the sample that I have shared was developed in Flash IDE. Code hinting works, debugging and preview also works for flash concurrency.

     

    Vinod

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2013 10:51 PM   in reply to ian10037

    Hi Ian

     

    I did further investigation on this. There is an issue with test movie. Where are the Debug Player is working fine. Hence debugging is possible. Thanks for pointing this out.

     

    Vinod

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 4, 2013 9:32 AM   in reply to ian10037

    Hey ian10037, I was just reading this page and came across your issue about using Workers within Flash Professinoal. There is a known issue that Adobe is tracking here:

    https://bugbase.adobe.com/index.cfm?event=bug&id=3578251

     

    The problem is in regards to ADL and debug mode in which the Adobe AIR SDK has not integrated support for Worker threads within ADL yet. Adobe says they are working on this issue, but they need more votes to up the priority. So if you go the bugbase you can add your vote there, and your problem with Workers would probably be fixed.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points