2014-02-27 126 views
0

我的目標是:使用一個FOR函數在10個動畫片段上設置位置並在動畫片段中顯示圖片。AS3 |使用加載器加載圖片時發生錯誤

我的代碼:

function loadOnePageItems(folderID:int):void { 
var it:int=1; 
var openURL:String; 
var loader:Loader = new Loader(); 

for (var i:int = 1; i <= loadedXML.folder[folderID].*.length(); i++) { 
    openURL = ("http://some_site.com/library/cut_img.php?src=" + loadedXML.folder[folderID][email protected] + '/' + loadedXML.folder[folderID].item[i-1][email protected] + '.' + loadedXML.folder[folderID].item[i-1][email protected] + '&w=87&h=64'); 
    loader.load(new URLRequest(openURL)); 
    MovieClip(mc_library.getChildByName('item_' + i)).showcase.addChild(loader); 

    switch (it) { 
     case 10 : 
      mc_library.item_10.x=189,00; 
      mc_library.item_10.y=485,55; 
      break; 
     case 9 : 
      mc_library.item_9.x=63,00; 
      mc_library.item_9.y=485,55; 
      break; 
     case 8 : 
      mc_library.item_8.x=189,00; 
      mc_library.item_8.y=375,55; 
      break; 
     case 7 : 
      mc_library.item_7.x=63,00; 
      mc_library.item_7.y=375,55; 
      break; 
     case 6 : 
      mc_library.item_6.x=189,00; 
      mc_library.item_6.y=265,55; 
      break; 
     case 5 : 
      mc_library.item_5.x=63,00; 
      mc_library.item_5.y=265,55; 
      break; 
     case 4 : 
      mc_library.item_4.x=189,00; 
      mc_library.item_4.y=155,55; 
      break; 
     case 3 : 
      mc_library.item_3.x=63,00; 
      mc_library.item_3.y=155,55; 
      break; 
     case 2 : 
      mc_library.item_2.x=189,00; 
      mc_library.item_2.y=45,55; 
      break; 
     case 1 : 
      mc_library.item_1.x=63,00; 
      mc_library.item_1.y=45,55; 
      break; 
     default : 
      trace("None of the numbers above"); 
      break; 
     } 
     it++; 
    } 
} 

當我開始只有最後一項得到 「裝載機」 的形象。圖片庫 - http://puu.sh/7cjxR.png

如何解決?

+0

對於初學者,您似乎是以歐洲格式('數字,小數)而不是'number.decimals'格式聲明所有位置。 – h2ooooooo

+0

你能舉個例子嗎? – Some1

+0

跟蹤'我'並檢查它是否真的遞增? –

回答

1

問題是,您只使用一個Loader並且只更改其網址。您應該將loader聲明移至循環中。這將創建Loader的多個實例,並且應交付所有圖像。

function loadOnePageItems(folderID:int):void { 
    var it:int=1; 
    var openURL:String; 

    for (var i:int = 1; i <= loadedXML.folder[folderID].*.length(); i++) { 
     openURL = ("http://some_site.com/library/cut_img.php?src=" 
     + loadedXML.folder[folderID][email protected] + '/' + loadedXML.folder[folderID].item[i-1][email protected] + '.' + loadedXML.folder[folderID].item[i-1][email protected] + '&w=87&h=64'); 
     var loader:Loader = new Loader(); 
     loader.load(new URLRequest(openURL)); 
     MovieClip(mc_library.getChildByName('item_' + i)).showcase.addChild(loader); 

    switch (it) { 
     case 10 : 
      mc_library.item_10.x=189,00; 
      mc_library.item_10.y=485,55; 
      break; 
     case 9 : 
      mc_library.item_9.x=63,00; 
      mc_library.item_9.y=485,55; 
      break; 
     case 8 : 
      mc_library.item_8.x=189,00; 
      mc_library.item_8.y=375,55; 
      break; 
     case 7 : 
      mc_library.item_7.x=63,00; 
      mc_library.item_7.y=375,55; 
      break; 
     case 6 : 
      mc_library.item_6.x=189,00; 
      mc_library.item_6.y=265,55; 
      break; 
     case 5 : 
      mc_library.item_5.x=63,00; 
      mc_library.item_5.y=265,55; 
      break; 
     case 4 : 
      mc_library.item_4.x=189,00; 
      mc_library.item_4.y=155,55; 
      break; 
     case 3 : 
      mc_library.item_3.x=63,00; 
      mc_library.item_3.y=155,55; 
      break; 
     case 2 : 
      mc_library.item_2.x=189,00; 
      mc_library.item_2.y=45,55; 
      break; 
     case 1 : 
      mc_library.item_1.x=63,00; 
      mc_library.item_1.y=45,55; 
      break; 
     default : 
      trace("None of the numbers above"); 
      break; 
     } 
     it++; 
    } 
} 
+0

我在動作小白你可以給我例子的代碼嗎? – Some1

+0

已被添加到答覆中。 –