using loader with worker

扶醉桌前 提交于 2019-12-11 16:28:18

问题


I want to load image from worker, but i get this error :

* Security Sandbox Violation * Connection to file:///C|/Users/Mudinho/Documents/projetos/as3/Engine/bin/TileSet/testeTileSet.png halted - not permitted from file:///C|/Users/Mudinho/Documents/projetos/as3/Engine/bin/Engine.swf -- Remote SWFs may not access local files.

Worker 2: [Fault] exception, information=SecurityError: Error #2148: SWF file file:///C|/Users/Mudinho/Documents/projetos/as3/Engine/bin/Engine.swf cannot access local resource file:///C|/Users/Mudinho/Documents/projetos/as3/Engine/bin/TileSet/testeTileSet.png. Only local-with-filesystem and trusted local SWF files may access local resources.

i already put the -use-network=false in compiler options, set "Use Network Services" to false, not running the swf via browser, the debug(Security.sandboxType); print remote

here is my worker code

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");
            }
            //}
        }
    }

}

-EDIT forgot to say already give worker giveAppPrivileges flag var bgWorker:Worker = WorkerDomain.current.createWorker(swfBytes, true);


回答1:


Concerning your error message, maybe you can fix using the giveAppPrivileges flag.

public function createWorker(swf:ByteArray, giveAppPrivileges:Boolean = false):Worker

giveAppPrivileges:Boolean (default = false) — indicates whether the worker should be given application sandbox privileges in AIR. This parameter is ignored in Flash Player.



来源:https://stackoverflow.com/questions/29114114/using-loader-with-worker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!