1

I'm trying to load images from google maps static images api into flash. When I attempt to load them flash complain about sandbox issues. Even after I try and load the policy file from google.

Security.loadPolicyFile("http://maps.googleapis.com/crossdomain.xml");

Is there any way around this? or is it simply impossible to load images in this fashion?

user379468
  • 3,989
  • 10
  • 50
  • 68
  • Are you testing this locally or from a web server? – crooksy88 May 29 '12 at 15:27
  • 1
    Please show some code. Loading an image from a different domain should not cause a security sandobx error. However, if you try to access the bit map data of such an image, it will generate a security error. – Sunil D. May 29 '12 at 15:36
  • I did solve this, you are correct, I was using a loader class and it was trying to check the status, which I guise involves accessing the data. – user379468 Jun 11 '12 at 15:31

1 Answers1

1
        var loader1:Loader = new Loader();
        var lctx1:LoaderContext = new LoaderContext(true);
        loader1.contentLoaderInfo.addEventListener(Event.INIT, doImgInit);
        loader1.load(new URLRequest("http://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=600x400&maptype=satellite&sensor=false&scale=4"), lctx1);
    private function doImgInit(evt:Event):void
    {
        trace("DO IT")
        // get a reference to the LoaderInfo object in which the image is loaded
        var lInfo:LoaderInfo = evt.target as LoaderInfo;

        // this variable is used as reference to the image in the end.
        var dO:DisplayObject;

        // try to access the "content" property of the loader, if it works, there is a crossdomain.xml file. 
        try{
            dO = lInfo.loader.content;
        } 

        // if there wasn't one, we need to put the loader inside another object in order to manipulate it
        catch(err:SecurityError)
        {
            // create a new Sprite to contain the loaded image
            var sprt:Sprite = new Sprite();
            // add the loader to the sprite
            sprt.addChild(lInfo.loader);
            // get a reference to this sprite in the dO variable
            var dO:DisplayObject = sprt as DisplayObject;
        }

        // from here on you can do anything to the dO variable, rotate it, draw it unto a bitmapData, move it around.. 
        // but first don't forget to add to to some container that is on the stage so you can see it!   
    }
user379468
  • 3,989
  • 10
  • 50
  • 68