2012-07-30 93 views
0

我正在創建一個Flash引擎,並且我有一個Loader類。當我在地圖中打開.swf文件時,它可以工作,但是當我在服務器上打開它時,它不會。 HTTP狀態返回200,所以這意味着它有一個連接,但圖像不顯示......這是如何造成的,我該如何解決它?Flash文件下載在服務器上不起作用

package com.loading{ 
import flash.display.Loader; 
import flash.media.Sound; 
import flash.net.URLRequest; 
import flash.events.Event; 
import flash.events.ErrorEvent; 
import flash.events.IOErrorEvent; 
import flash.events.EventDispatcher; 
import com.events.LoaderEvent; 
import flash.media.SoundChannel; 
import flash.events.HTTPStatusEvent; 

public class Loader extends EventDispatcher { 

    public var returnImages:Array = new Array(); 

    public var totalImages:int = 0; 

    public function Loader() { 
    } 

    public function LoadImage(path:String) { 
     var imgLoader:flash.display.Loader = new flash.display.Loader(); 
     imgLoader.contentLoaderInfo.addEventListener(LoaderEvent.COMPLETE, loadImageComplete); 
     imgLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpError,false,0,true); 
     imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, error, false, 0 ,true); 
     imgLoader.load(new URLRequest(path)); 
     totalImages = 1; 
    } 

    public function LoadImages(paths:Vector.<String>) { 
     totalImages = paths.length; 
     for (var i:int = 0; i<paths.length; i++) { 
      var imgLoader:flash.display.Loader = new flash.display.Loader(); 
      imgLoader.contentLoaderInfo.addEventListener(LoaderEvent.COMPLETE, loadImageComplete); 
      imgLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpError,false,0,true); 
      imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, error, false, 0 ,true); 
      imgLoader.load(new URLRequest(paths[i])); 
     } 
    } 

    private function loadImageComplete(e:Event) { 
     returnImages.push(e.target.content); 
     if (returnImages.length == totalImages) { 
      dispatchEvent(new LoaderEvent(LoaderEvent.ALL_IMAGES_LOADED,0,totalImages,true)); 
     } else { 
      dispatchEvent(new LoaderEvent(LoaderEvent.IMAGE_LOADED,returnImages.length,totalImages,true)); 
     } 
    } 

    private function error(e:IOErrorEvent) { 
     dispatchEvent(new LoaderEvent(LoaderEvent.ERROR,0,0,e.text,true)); 
    } 

    private function httpError(e:HTTPStatusEvent) { 
     if (e.status != 200) { 
      dispatchEvent(new LoaderEvent(LoaderEvent.ERROR,0,0,e.status,true)); 
     } 
    } 



} 

} 

,這是它是如何加載:

var lo:com.loading.Loader = new com.loading.Loader(); 
lo.LoadImage("http://s3files.core77.com/blog/images/Balloon-Tank.jpg"); 
lo.addEventListener(LoaderEvent.ERROR, error, false, 0 ,true); 
lo.addEventListener(LoaderEvent.ALL_IMAGES_LOADED,loadImage, false, 0, true); 
function loadImage(e:LoaderEvent) { 
for (var i:int =0; i<e.totalPosition; i++) { 
    info.appendText("Loaded Image: " + i+"\n"); 
    try { 
     var tempBitmap:Bitmap = lo.returnImages[i]; 
     tempBitmap.scaleX = tempBitmap.scaleY = 2; 
     tempBitmap.alpha = 0.5; 
     addChild(tempBitmap); 
    } catch (error:Error) { 
     info.appendText("Catched Error: " + error.toString() + "\n"); 
    } 
} 
} 

function error(e:LoaderEvent) { 
info.appendText("Error: " + e.currentString+"\n"); 
} 
+0

請問當我在本地運行它時,「當我在地圖上打開swf」這個語句是否有效?您是否將SWF部署到圖像託管的相同子域? – 2012-07-30 21:01:52

+0

不,它是在本地打開的,鏈接只是我在谷歌上發現的一個隨機圖像來測試它。但我給了完整的域名,所以它應該加載,因爲它在本地... – tversteeg 2012-07-30 22:40:54

回答

1

我認爲當你創建一個從加載圖像的新Bitmap,並試圖操縱其scalealpha屬性你遇到一個跨域問題。快速解決方法是從SWF託管的同一臺服務器加載測試映像。

如果您對與Flash相關的跨域策略感興趣,則應該閱讀(相當深奧)Adobe documentation,特別是標題爲「遍歷顯示列表」的部分。

+0

你說得對,它必須與跨域權利。我只需要這樣做:Security.allowDomain(「URLfromSite」); – tversteeg 2012-07-31 10:42:04

相關問題