6 Replies Latest reply: Sep 4, 2013 9:32 AM by Jeff-uGenius RSS

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

    ian10037 Community Member

      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....

        • 1. Re: Is it possible to use workers if one develops in the Flash IDE?
          Vinod Menon@Adobe Adobe Employee

          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-5856a8af1390d64d08c-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

          • 2. Re: Is it possible to use workers if one develops in the Flash IDE?
            ian10037 Community Member

            Hi Vinod,

             

             

            Thanks for contributing - but the problem wasn't the coding, it's that none of it worked within the Flash Professional IDE.

             

            I have since found that it will work fine if i test in a web browser - although then I lose the ability to trace (not sure that works from workers anyway).

             

            Since i use a custom Logger class, that wasn't too much of a problem for me, but it would still be nice to be able to test in Flash Professional rather than having to launch in the browser...

             

            Ian

            • 3. Re: Is it possible to use workers if one develops in the Flash IDE?
              Vinod Menon@Adobe Adobe Employee

              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

              • 4. Re: Is it possible to use workers if one develops in the Flash IDE?
                ian10037 Community Member

                Hi Vinod,

                 

                 

                Again, thanks for responding - maybe this is something for the installer team? I donwloaded the trial version of Flash CC on 24th June and made no changes to the installed set up at all. I'm using an iMac running 10.6.8.

                 

                Using the IDE as downloaded, and testing using new files targetted at player 11.7, I cannot access any concurrency features if I test within the IDE - and Worker.isSupported returns false. Code hinting does work however and code does run without problem in a browser or if I open the swf with the flash player from the finder.

                 

                I can preview the swf I'm using to create the worker in the normal way in the IDE.

                 

                As I'm on a fairly tight timeline on this, I'm going to get on eithout investigating further - it's irritating, but no more.

                 

                Thanks again for your help.

                 

                Ian

                • 5. Re: Is it possible to use workers if one develops in the Flash IDE?
                  Vinod Menon@Adobe Adobe Employee

                  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

                  • 6. Re: Is it possible to use workers if one develops in the Flash IDE?
                    Jeff-uGenius Community Member

                    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.