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

forked from: ActionScript Worker test

Get Adobe Flash player
by bkzen 06 Feb 2013
  • Forked from bkzen's ActionScript Worker test
  • Diff: 50
  • Related works: 4
  • Talk

    makc3d at 06 Feb 2013 20:06
    white screen here (
    bkzen at 06 Feb 2013 20:40
    @makc3d Google Chrome? or under FlashPlayer11.5? Google Chrome(PPAPI) is not supported Actionscript Worker.
    makc3d at 06 Feb 2013 21:42
    oh shit, indeed
    makc3d at 13 Feb 2013 12:07
    btw http://labs.stackandheap.com/detecting-pepper-based-flash-player/
    bkzen at 13 Feb 2013 12:54
    @makc3d thanks!

    Tags

    Embed
/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cVOL
 */

package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.system.Capabilities;
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.system.MessageChannel;
    import flash.system.Worker;
    import flash.system.WorkerDomain;
    import flash.utils.ByteArray;
    public class FlashTest extends Sprite {
        private var worker:Worker;
        private var messageChannel:MessageChannel;
        private var bmd:BitmapData;
        private var bmp:Bitmap;
        private var bytes: ByteArray;
        public function FlashTest() {
            // write as3 code here..
            var version: Array = Capabilities.version.split(" ")[1].split(",");
            if (!Worker.isSupported || !(version[0] >= 11 && version[1] >= 5) )
            {
                var txt:TextField = new TextField();
                txt.autoSize = "left";
                txt.text = "Not support";
                addChild(txt);
                return;
            }
            bmd = new BitmapData(1024, 1024, true, 0);
            if (Worker.current.isPrimordial)
            {
                txt = new TextField();
                txt.autoSize = "left";
                bmp = new Bitmap(bmd, "auto", true);
                bytes = bmd.getPixels(bmd.rect);
                bytes.shareable = true;
                worker = WorkerDomain.current.createWorker(loaderInfo.bytes);
                messageChannel = worker.createMessageChannel(Worker.current);
                worker.setSharedProperty("_test_channel", messageChannel);
                worker.setSharedProperty("bytes", bytes);
                worker.start();
                txt.text = messageChannel.receive(true);
                addChild(bmp);
                addChild(txt);
                addEventListener(Event.ENTER_FRAME, mainLoop);
            }
            else 
            {
                messageChannel = Worker.current.getSharedProperty("_test_channel");
                bytes = Worker.current.getSharedProperty("bytes");
                messageChannel.send("hogemoja");
                addEventListener(Event.ENTER_FRAME, workersLoop);
            }
        }
        
        private function mainLoop(e: Event): void 
        {
            bmd.lock();
            bytes.position = 0;
            bmd.setPixels(bmd.rect, bytes);
            bmd.unlock();
        }
        
        private function workersLoop(e:Event):void 
        {
            var offsets: Array = [], n: int = 12;
            for (var i:int = 0; i < n; i++) 
            {
                offsets[i] = new Point();
            }
            for (i = 0; i < 3; i++ )
            {
                bmd.perlinNoise(10, 10, n, Math.random() * 0xFFFFFF, true, true, 7, false, offsets);
            }
            bytes.position = 0;
            bmd.copyPixelsToByteArray(bmd.rect, bytes);
        }
    }
}