title: execute remote SWF in AIR Security Sandbox
body: <p>I try to download an external SWF and run it within the AIR security sandbox.</p>
  
  <p>this is the code of the AIR application:</p>
  
  <pre><code>public class Downloader extends Sprite
  {
  
      private static const REMOTE_FILE:URLRequest = new URLRequest("http://myserver.com/downloadable.swf");
      private var _main:NativeWindow;
  
      public function Downloader()
      {
          var loader:URLLoader = new URLLoader(REMOTE_FILE);
          loader.dataFormat = URLLoaderDataFormat.BINARY;
          loader.addEventListener(Event.COMPLETE, downloadComplete);
      }
  
      private function downloadComplete(e:Event):void{
          var ba:ByteArray = e.target.data;
          var stream:FileStream = new FileStream();
          var file:File = File.applicationStorageDirectory.resolvePath("downloadable.swf");
          stream.open(file, FileMode.WRITE);
          stream.writeBytes(ba);
          stream.close();
  
          loadAndRunSwf();
      }
  
      private function loadAndRunSwf(){       
          this._main = new NativeWindow();
          this._main.width = 1024;
          this._main.height = 768;
  
                      ////obsolete?
          //var context:LoaderContext = new LoaderContext();
          //context.allowLoadBytesCodeExecution = true;
          //context.applicationDomain = ApplicationDomain.currentDomain;  
  
          var file:File = File.applicationStorageDirectory.resolvePath("downloadable.swf");
          var loader:Loader = new Loader();
          loader.load(new URLRequest(file.url)/*,context*/);
  
          this._main.stage.addChild(loader);
          this._main.activate();
      }
  }
  </code></pre>
  
  <p>Code of the downloadable.swf:</p>
  
  <pre><code>public class Downloadable extends Sprite
  {
      private var _btn:Button = new Button();
      private var _baseFolder:File = new File("app-storage:/");
  
      public function downloadable_test()
      {
          this.addChild(_btn);
          _btn.label = "access Harddisk";
                      ...
      }
  }
  </code></pre>
  
  <p>so now, If I run Downloader, it will download the swf and try to run it, but i'll get an exception in Downloadable on the line</p>
  
  <pre><code>    private var _baseFolder:File = new File("app-storage:/");
  </code></pre>
  
  <p>the error:</p>
  
  <pre><code>SecurityError: file
  at runtime::SecurityManager$/checkPrivilegeForCaller()
  </code></pre>
  
  <p>So - what Do I need to do to prevent such security errors? I want my remote SWF to be treated as native code running in the same security sandbox as the AIR code.</p>