在AIR安全沙箱中执行远程SWF
|
我尝试下载一个外部SWF并在AIR安全沙箱中运行它。
这是AIR应用程序的代码:
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();
}
}
downloadable.swf的代码:
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\";
...
}
}
所以现在,如果我运行Downloader,它将下载swf并尝试运行它,但是我将在Downloadable中得到一个例外
private var _baseFolder:File = new File(\"app-storage:/\");
错误:
SecurityError: file
at runtime::SecurityManager$/checkPrivilegeForCaller()
所以-我需要怎么做才能防止此类安全错误?我希望将远程SWF视为在与AIR代码相同的安全沙箱中运行的本机代码。
没有找到相关结果
已邀请:
2 个回复
bab
播匣扦阔食