2014-01-30 20 views
0

我的URL請求在Flash Pro中完美運行,但是當我在瀏覽器中測試它時,圖像根本不起作用。它不加載。是否有我需要使用的發佈設置?AS3 URLRequest在瀏覽器中不起作用

請幫忙,這很令人沮喪。 Here's它在瀏覽器中的樣子。

相關代碼:

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(); 
    } 
+0

Flash無法從比它託管,除非一個有效的跨域政策的另外一個Web服務器加載數據是在目標服務器上進行。閱讀更多: - http://www.adobe.com/devnet/flashplayer/articles/cross_domain_policy.html –

+0

這個答案幫了我很多,相同的問題 http://stackoverflow.com/questions/13131638/flash-cs6- AS3 - 測試 - 電影中的瀏覽器 - 不工作 –

回答

1

你有一個安全錯誤:

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 http://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]:

相關問題