我想从worker加载图片,但是我收到了这个错误:
*安全沙箱违规* 与文件的连接:/// C | /Users/Mudinho/Documents/projetos/as3/Engine/bin/TileSet/testeTileSet.png 停止 - 不允许 文件:/// C | /Users/Mudinho/Documents/projetos/as3/Engine/bin/Engine.swf - 远程SWF可能无法访问本地文件。
Worker 2:[Fault]异常,information = SecurityError:错误#2148: SWF文件 文件:/// C | /Users/Mudinho/Documents/projetos/as3/Engine/bin/Engine.swf 无法访问本地资源 文件:/// C | /Users/Mudinho/Documents/projetos/as3/Engine/bin/TileSet/testeTileSet.png。 只能访问本地文件系统和受信任的本地SWF文件 当地资源。
我已将-use-network = false放在编译器选项中,将“Use Network Services”设置为false, 不通过浏览器运行swf,调试(Security.sandboxType);打印远程
这是我的工人代码
package {
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.MessageChannel;
import flash.system.Security;
import flash.system.Worker;
import flash.system.WorkerDomain;
import flash.utils.ByteArray;
import starling.core.Starling;
import starling.textures.Texture;
import starling.utils.AssetManager;
/**
* ...
* @author
*/
public class SlaveWorker extends Sprite {
private var miso:MessageChannel;
private var mosi:MessageChannel;
private var byteArray:ByteArray;
//private var asset:AssetManager;
private var loader:Loader;
private var asset:AssetManager;
private var starling:Starling;
private function debug(... arguments):void {
if (Worker.current.isPrimordial) {
trace("Master[1] : " + arguments);
} else {
trace("Worker[" + Worker.current.getSharedProperty("worker") + "] : " + arguments);
}
}
public function SlaveWorker(mosi_:MessageChannel, miso_:MessageChannel, byteArray_:ByteArray) {
Security.allowInsecureDomain("*");
Security.allowDomain("*");
Security.allowInsecureDomain(Security.pageDomain);
Security.allowDomain(Security.pageDomain);
debug(Security.sandboxType);
miso = miso_;
mosi = mosi_;
byteArray = byteArray_;
//asset = new AssetManager();
mosi.addEventListener(Event.CHANNEL_MESSAGE, onMosi);
//asset = new AssetManager();
addEventListener(Event.ADDED_TO_STAGE, onAdded);
loader = new Loader();
}
private function onAdded(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAdded);
//starling = new Starling(Inutil, this.stage);
}
private var archiveType:String;
private var archiveName:String;
private function onMosi(evt:Event):void {
var command:* = mosi.receive();
debug(command);
if (command is String) {
if (command == "loadArchive") {
var type:* = mosi.receive();
var archive:* = mosi.receive();
debug(type);
debug(archive);
if (type == "texture") {
archiveType = type;
archiveName = archive;
var _sair:Boolean = false;
while (!_sair) {
var pos:int = archiveName.search("/");
if (pos < 0)
_sair = true;
else
archiveName = archiveName.slice(pos + 1);
debug(archiveName);
}
archiveName = archiveName.slice(0, archiveName.search(".") - 1);
debug("arquivo a carregar " + archive);
var lc:LoaderContext = new LoaderContext();
lc.checkPolicyFile = false;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onArchiveLoaded);
//asset.enqueue(archive);
//asset.loadQueue(onArchiveLoaded);
loader.load(new URLRequest(archive), lc);
debug("lol");
}
}
}
}
private function onArchiveLoaded(e:Event):void {
var _loader:Loader = e as Loader;
//if (value == 1.0) {
debug("carregado " + _loader.contentLoaderInfo.bytesLoaded + " bytes");
if (archiveType == "texture") {
//var texture:Texture = asset.get
debug("data type" + _loader.contentLoaderInfo.contentType);
byteArray.clear();
//byteArray.writeObject(asset.getTexture(archiveName));
var bitmapData:BitmapData = _loader.content as BitmapData;
byteArray.writeObject(Texture.fromBitmapData(bitmapData));
miso.send("STATUS");
miso.send("COMPLETE");
}
//}
}
}
}
- 编辑 忘了说 已经给工人giveAppPrivileges标志 var bgWorker:Worker = WorkerDomain.current.createWorker(swfBytes,true);
答案 0 :(得分:1)
关于您的错误消息,也许您可以使用giveAppPrivileges标志进行修复。
public function createWorker(swf:ByteArray, giveAppPrivileges:Boolean = false):Worker
giveAppPrivileges:Boolean(default = false) - 指示是否应在AIR中为worker提供应用程序沙箱权限。 Flash Player中将忽略此参数。