Question
Security sandbox conflict when I Load atf by worker(flash player of Web browser)
MainSwf:
private function loadWorker():void{
Security.allowInsecureDomain("*");
Security.allowDomain("*");
var workerLoader:URLLoader = new URLLoader();
workerLoader.dataFormat = URLLoaderDataFormat.BINARY;
workerLoader.addEventListener(Event.COMPLETE, loadComplete);
workerLoader.load(new URLRequest("workerSwf.swf"));
}
private function loadComplete(event:Event):void
{
// create the background worker
var workerBytes:ByteArray = event.target.data as ByteArray;
var worker:Worker = WorkerDomain.current.createWorker(workerBytes, true);
// listen for worker state changes to know when the worker is running
worker.addEventListener(Event.WORKER_STATE, workerStateHandler);
//build
mainToWorker = Worker.current.createMessageChannel(worker);
workerToMain = worker.createMessageChannel(Worker.current);
//init worker name
worker.setSharedProperty("mainToWorker", mainToWorker);
worker.setSharedProperty("workerToMain", workerToMain);
workerToMain.addEventListener(Event.CHANNEL_MESSAGE, onWorkerToMain);
worker.start();
}
private function workerStateHandler(e:Event):void{
_workerInit = true;
mainToWorker.send(1);
}
workerSwf:
private function init():void{
Security.allowInsecureDomain("*");
Security.allowDomain("*");
//init worker by name
mainToWorker = Worker.current.getSharedProperty("mainToWorker");
workerToMain = Worker.current.getSharedProperty("workerToMain");
//addEventListener
mainToWorker.addEventListener(Event.CHANNEL_MESSAGE, onMainToWorker);
}
public function onMainToWorker(event:Event):void {
//load atf
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
var r:URLRequest = new URLRequest("1.atf");
loader.load(r);///// throw Error:Security sandbox conflict
//SecurityError: Error #2148:
// SWF file file:///D:/A/bin-debug/boot.swf Local resources cannot be accessed file:///D:/A/bin-debug/1.atf。
//The Local resources can be accessed by the SWF of File system and trusted Local SWF.
//at flash.net::URLStream/load()
//at flash.net::URLLoader/load()
//
loader.addEventListener(Event.COMPLETE, onComp);
loader.addEventListener(IOErrorEvent.IO_ERROR, onErr);
function onComp(e:Event):void{
var bytes:ByteArray = loader.data as ByteArray;
bytes.shareable = true;
workerToMain.send(bytes);
}
function onErr(e:IOErrorEvent):void{
workerToMain.send(0);
}
}