我需要從ZIP壓縮文件中加載多個圖像,並在加載ZIP壓縮文件中的所有文件後執行一些操作。我使用FZip庫來處理ZIP文件。我的問題是,有時候所有文件的加載都不會執行。Flash:加載多張圖片及其滿載的期望
在這段代碼我開始加載過程:
loadedImages = zip.getFileCount();
trace("Starting... " + loadedImages);
for (var i:uint = 0; i < loadedImages; i++)
{
var file:FZipFile = zip.getFileAt(i);
// NamedLoader - common flash.display.Loader who remembers the name of the file
var pictLdr:Loader = new NamedLoader(file.filename);
trace("start " + i);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
pictLdr.loadBytes(file.content, new LoaderContext(false, ApplicationDomain.currentDomain));
}
private function imageLoaded(e:Event):void
{
// do some actions, like getting file content and store it
trace("Loaded: " + loadedImages);
loadedImages--;
// if all images has been loaded, I show some scene
if (loadedImages == 0)
{
showScene();
}
}
有時候,不是所有的圖片下載的,我有這樣的跟蹤輸出:
Starting... 36
start 0
start 1
start 2
start 3
start 4
start 5
start 6
start 7
start 8
start 9
start 10
start 11
start 12
start 13
start 14
start 15
start 16
start 17
start 18
start 19
start 20
start 21
start 22
start 23
start 24
start 25
start 26
start 27
start 28
start 29
start 30
start 31
start 32
start 33
start 34
start 35
Loaded: 36
Loaded: 35
Loaded: 34
Loaded: 33
Loaded: 32
Loaded: 31
Loaded: 30
Loaded: 29
Loaded: 28
Loaded: 27
Loaded: 26
Loaded: 25
Loaded: 24
Loaded: 23
Loaded: 22
Loaded: 21
Loaded: 20
Loaded: 19
Loaded: 18
Loaded: 17
Loaded: 16
Loaded: 15
Loaded: 14
Loaded: 13
可以看出,所有的裝載機開始,但不是所有的光潔度。沒有例外發生,有時會發生。我不明白爲什麼。
您是否嘗試過使用Fiddler或Firebug來查看發生故障的請求的情況? – 2010-02-26 05:00:43
是的,我試過。如果我關閉瀏覽器緩存,那麼發送GET查詢,並且答案是OK(200)。但有時圖像不能完全加載。 – 2010-02-26 06:50:45