In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ActionScript Worker test

Get Adobe Flash player
by bkzen 25 Sep 2012
/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qCyc
 */

package {
    import flash.events.Event;
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.system.MessageChannel;
    import flash.system.Worker;
    import flash.system.WorkerDomain;
    public class FlashTest extends Sprite {
        private var worker:Worker;
        private var messageChannel:MessageChannel;
        public function FlashTest() {
            // write as3 code here..
            if (Worker.current.isPrimordial)
            {
                var txt:TextField = new TextField();
                txt.autoSize = "left";
                addChild(txt);
                worker = WorkerDomain.current.createWorker(loaderInfo.bytes);
                messageChannel = worker.createMessageChannel(Worker.current);
                worker.setSharedProperty("_test_channel", messageChannel);
                worker.start();
                txt.text = messageChannel.receive(true);
            }
            else 
            {
                messageChannel = Worker.current.getSharedProperty("_test_channel");
                messageChannel.send("hogemoja");
            }
        }
    }
}