title: AS3 can not load a Bitmap by using loadByte in Thread?
body: <p>Flash Player supported Thread in 11.5+.</p>
  
  <p>I want to load an image by using Loader.loadBytes() in Worker Thread.</p>
  
  <p>Which the Image ByteArray are generated in Main Thread.</p>
  
  <p>But I can NOT do it. </p>
  
  <p>I got a SecurityError like this:</p>
  
  <blockquote>
    <p>SecurityError: Error #2123: Security sandbox violation:
    Loader.content: file:///E:/work/ASWorkSpace/test/bin-debug/test.swf
    cannot access
    file:///E:/work/ASWorkSpace/test/bin-debug/test.swf/[[DYNAMIC]]/1. No
    policy files granted access.</p>
  </blockquote>
  
  <p>I init my worker thread like:</p>
  
  <pre><code>worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes);
  </code></pre>
  
  <p>so it's not a swf from remote, but it's local or like </p>
  
  <pre><code>[Embed(source="../workerswfs/Thread.swf", mimeType="application/octet-stream")]
  </code></pre>
  
  <p>I found in <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html" rel="nofollow">manual</a>.
  It said "If the loaded content is an image, its data cannot be accessed by a SWF file outside of the security sandbox, unless the domain of that SWF file was included in a URL policy file at the origin domain of the image."</p>
  
  <p>I have gotten a solution. I loadByte() twice, it seems "washed off" the ByteArray source. so FlashPlayer considered the ByteArray generated by Worker Thread, and it allowed to access loader.content. Like this:</p>
  
  <pre><code>            //Messages to the Main thread
          protected function onMainToWorker(event:Event):void {
              var msg:ByteArray = mainToWorker.receive() as ByteArray;
              trace(msg.length);
              var loader:Loader = new Loader();
              loader.contentLoaderInfo.addEventListener(Event.COMPLETE, bytesComplete);
              var bytes:ByteArray = new ByteArray();
              bytes.writeBytes(msg,0,msg.length);
              loader.loadBytes(bytes);
          }
  
          private function loadedAagin(e:Event):void
          {
              var loader:Loader = (e.target as LoaderInfo).loader;
                      // Here we can access it.
              var bmp:Bitmap = loader.content as Bitmap;
          }
          private function bytesComplete(e:Event):void
          {
              var loader:Loader = (e.target as LoaderInfo).loader;
              loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, bytesComplete);
  
              // var bmp:Bitmap = loader.content as Bitmap;  It can not be accessed
              // just loadBytes again, it seems "washed off" the ByteArray source
  
              var newloader:Loader = new Loader();
              newloader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedAagin);
              newloader.loadBytes(loader.contentLoaderInfo.bytes);
          }
  </code></pre>
  
  <p>But it's so ugly isn't it?
  Is there anyone has good idea?</p>