2012-12-01 148 views
1

我正在製作我的第一個Flash照片庫,當我點擊縮略圖時,它應該以全尺寸顯示圖片並以百分比形式顯示預編碼器。這一切都在Flash下載模擬器上離線工作,但在線上,百分比不會顯示出來。它有時會開始顯示100%左右或根本不顯示。畫廊的 鏈接:http://solarratko.netii.net/ 下面是從我的類一些代碼,加載全尺寸圖像圖片預加載百分比

public function kreni(f:String) //function that start when user click on thumbnail 
    { 
     URLrequest=new URLRequest(f); //URLrequest for image in full size 
     dspLoader.load(URLrequest); //loading the image 

     preloader.visible = true;//prelaoder that shows up is visible 
     h.visible=true;//text area for percentage is visible 
     dspLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progres);//adding progress event 
     dspLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, kraj);//adding complete event 

    } 
    public function progres(e:Event):void 
    { 
     var perc:Number = e.target.bytesLoaded/e.target.bytesTotal;//calculatin percentage 
     h.text = Math.ceil(perc*100).toString();//displaying percentage wich is not working online or it start too late 

    } 
    public function kraj(e:Event):void 
    { 
     h.text=""; 
     preloader.visible = false; 
     h.visible=false; 
    } 

回答

0

似乎是爲我工作的罰款。你清除了你的緩存嗎?預加載器是否不顯示並且不加載圖像?

如果您想強制預加載器運行,您可以爲加載序列分配一個計時器來檢查加載的內容。加載時啓動定時器,並確保百分比等於或大於您在定時器回調中執行的檢查 - 使用進度回調獲取加載的字節。因此,計時器可以是0.5秒,如果圖像在緩存中,您會在圖像加載之前看到快速預加載器。

*編輯*

public function kreni(f:String) //function that start when user click on thumbnail { 

    preloader.visible = true;//prelaoder that shows up is visible 
    h.visible=true;//text area for percentage is visible 

    URLrequest=new URLRequest(f); //URLrequest for image in full size 
    dspLoader.load(URLrequest); //loading the image 

    dspLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progres);//adding progress event 
    dspLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, kraj);//adding complete event 

} 
+0

我的問題是,顯示比例的文本沒有顯示出來。預加載器總是顯示出來,但文本在加載圖像結束時顯示(100%)。 – Ratko

+0

編輯上面的代碼 - 嘗試在調用負載之前將對象的可見性設置爲true,並查看是否有任何區別 – Gone3d

+0

仍然不起作用。我只注意到文字顯示出來,因爲我的鼠標光標正在改變。看起來就像進展事件沒有觸發,但仍然不知道爲什麼。在Flash模擬下載,一切正常。我還注意到一件事。有時,但非常罕見的進度事件按時開始,文本顯示百分比,但通常以100%開始或根本不開始。 – Ratko