5 Replies Latest reply on Nov 11, 2010 9:35 AM by rmklein

    Error #2148 when loading image from ByteArray (not network or file)

    Anastasiy Safari Level 1



      When I try to access bitmap data of Image loaded from ByteArray, I receive the following error:

      Error #2148: SWF file file:///C|/blablabla..../MyFlash.swf cannot access local resource file:///C|/blablabla..../MyFlash.swf/[[DYNAMIC]]/2. Only local-with-filesystem and trusted local SWF files may access local resources.


      I'm on Flash, not on AIR. And ByteArray contains PNG data which I prepare myself

      I tried to do it with Image.load and loader.loadBytes - the error is the same. I tried to use Flex SDK 3.4, 3.5 & 3.6 - nothing helps.

      When I add this image to my stage, it is displayed absolutely OK, but I still can't access bitmapData of this image - always got the same error.


      Flash Player 10


      Here are the samples of my code:


                public function onLoadComplete(event:Event):void
                  var loader:LoaderInfo = event.target as LoaderInfo;
                  var bmp:Bitmap = loader.loader.content as Bitmap; <-- here I received the error
                  var bmpDat:BitmapData = bmp.bitmapData;
                  this.bitmapData.copyPixels(bmpDat,new Rectangle(0,0,width,height), new Point(0,0));



                  var loader:Loader = new Loader();
                  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);


      And another try


             var image: Image = new Image()


             image.addEventListener(FlexEvent.UPDATE_COMPLETE, onCompleteLoad2 );



            public function onCompleteLoad2 (e:flash.events.Event):void
                       var image:Image=e.target as Image;
                       var bitmapData:BitmapData;
                       bitmapData=new BitmapData(image.width,image.height,true,0);             
                       bitmapData.draw(image); <-- here I received the error, while image is correctly added to the stage and displayed



      What's wrong? It seems, the image loaded from byteArray is treated as local resource. How can I overcome it inside the code? Because this .swf is

      run on different computers and I can't just add a flash security exception on every of them....


      Please, help I spent, maybe 20 hours and still can't find the solution