【问题标题】:Loading google maps static images into flash将谷歌地图静态图像加载到闪存中
【发布时间】:2012-06-03 19:22:24
【问题描述】:

我正在尝试将来自谷歌地图静态图像 api 的图像加载到闪存中。当我尝试加载它们时,闪存会抱怨沙盒问题。即使在我尝试从谷歌加载策略文件之后。

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

有没有办法解决这个问题?还是根本不可能以这种方式加载图像?

【问题讨论】:

  • 您是在本地测试还是从 Web 服务器测试?
  • 请显示一些代码。从不同的域加载图像不应导致安全 sandobx 错误。但是,如果您尝试访问此类图像的位图数据,则会产生安全错误。
  • 我确实解决了这个问题,你是对的,我使用的是加载器类,它试图检查状态,我认为这涉及访问数据。

标签: actionscript-3 flash google-maps cross-domain-policy


【解决方案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!   
    }

【讨论】:

  • 您是否能够在不遇到沙盒问题的情况下绘制位图数据?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-07
  • 1970-01-01
相关资源
最近更新 更多