AS3 Urlrequest在浏览器中不工作



我的URL请求在Flash Pro中可以很好地工作,但是当我在浏览器中测试它时,图像根本不起作用。它没有加载。我需要使用的发布设置吗?

请帮忙,这非常令人沮丧。这就是它在浏览器中时的样子。

相关代码:

    public function startSlidingPuzzle() {
        // blank spot is the bottom right
        blankPoint = new Point(numPiecesHoriz-1,numPiecesVert-1);
        // load the bitmap
        loadBitmap("http://fc07.deviantart.net/fs71/f/2014/030/d/7/slidingimage_by_nooodisaster-d74et6t.jpg");
    }
    // get the bitmap from an external source
    public function loadBitmap(bitmapFile:String) {
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingDone);
        var request:URLRequest = new URLRequest(bitmapFile);
        loader.load(request);
    }
    // bitmap done loading, cut into pieces
    public function loadingDone(event:Event):void {
        // create new image to hold loaded bitmap
        var image:Bitmap = Bitmap(event.target.loader.content);
        pieceWidth = image.width/numPiecesHoriz;
        pieceHeight = image.height/numPiecesVert;
        trace(numPiecesHoriz)
        // cut into puzzle pieces
        makePuzzlePieces(image.bitmapData);
        // shuffle them
        shufflePuzzlePieces();
    }

您有一个安全错误:

SecurityError: Error #2122: Security sandbox violation: Loader.content: http://fc03.deviantart.net/fs71/f/2014/030/e/e/beyonce_slidingpuzzle___flash_diary_day_10_by_nooodisaster-d74er8h.swf cannot access https://i.stack.imgur.com/ls9QI.jpg. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
at flash.display::Loader/get content()
at SlidingPuzzle/loadingDone()

尝试添加安全上下文:

public function loadBitmap(bitmapFile:String)
{
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingDone);
    var context:LoaderContext = new LoaderContext();
    context.applicationDomain = ApplicationDomain.currentDomain;
    context.securityDomain = SecurityDomain.currentDomain;
    context.checkPolicyFile = true;
    var request:URLRequest = new URLRequest( bitmapFile );
    loader.load( request, context );
}

如果无法解决它,则需要将crossdomain.xml添加到托管所请求的图像的服务器。为什么不在本地保存图像并将它们与您的构建相同的范围部署?

[1]:

相关内容

最新更新