2012-10-02 39 views
0

這裏是我的代碼:的attachMovie()不工作

var people:Array = [ 
    { 
     image: "1.jpg", 
     labels: 
      [ 
       "Valium dependant", 
       "Anger issues", 
       "Single parent" 
      ] 
    },{ 
     image: "2.jpg", 
     labels: 
      [ 
       "Alcoholic", 
       "Bipolar disorder", 
       "Smokes cannabis" 
      ] 
    },{ 
     image: "3.jpg", 
     labels: 
      [ 
       "Glue sniffer", 
       "Suffers from anxiety", 
       "Has terminal cancer" 
      ]  
    },{ 
     image: "4.jpg", 
     labels: 
      [ 
       "Ecstasy user", 
       "Binge drinker", 
       "Depressed" 
      ]  
    },{ 
     image: "5.jpg", 
     labels: 
      [ 
       "Homeless", 
       "Heroin user", 
       "Smokes" 
      ]  
    },{ 
     image: "6.jpg", 
     labels: 
      [ 
       "Uses poppers", 
       "LSD user", 
       "Cocaine user" 
      ]  
    } 
]; 

var thumb_container:MovieClip = this.thumb_container; 
for (index in people) { 
    var thumb:MovieClip = thumb_container.attachMovie("Thumbnail", "thumb_" + index, thumb_container.getNextHighestDepth()); 
    var image_container:MovieClip = thumb.image_container; 
    var image:MovieClip = image_container.attachMovie(people[index].image, "image_" + index, image_container.getNextHighestDepth()); 
    trace(image); 
} 

問題是trace(image)回報_level0.thumb_container.thumb_0.image_container這是image父。我無法弄清楚爲什麼它沒有返回我附加的圖像(圖像沒有出現在SWF中)。

注意:people數組中的image屬性是爲ActionScript導出的鏈接ID。

編輯:如果我把它們放在一個影片剪輯並加載它們,他們工作得很好,但似乎有很多人使用attachMovie()與圖像

+0

數組'people'中的'image'屬性在**庫**或** url **中爲外部資源保存**鏈接ID **嗎? – Moorthy

+0

@Moorthy它擁有庫中圖像的鏈接ID –

+0

你的代碼對我有用(它會記錄圖像並將其顯示在圖像容器中)。但是沒有爲任何mc設置位置,所以你應該確保'thumb' movieclip從不相互重疊。 – Moorthy

回答

0

您不能加載使用MovieClip.attachMovie位圖,因爲它不能識別位圖文件。目的是僅加載影片剪輯而不是其他類型。所以你必須先製作位圖數據,然後將這個位圖數據附加到動畫片段。

var thumb_container:MovieClip = this.thumb_container; 
for (index in people) { 
    var thumb:MovieClip = thumb_container.attachMovie("Thumbnail", "thumb_" + index, thumb_container.getNextHighestDepth()); 
    var image_container:MovieClip = thumb.image_container; 
    var bmp:BitmapData = BitmapData.loadBitmap(people[index].image); 
    var image:MovieClip = image_container.attachBitmap(bmp, image_container.getNextHighestDepth()); 
    trace(image); 
} 

它返回image並顯示它。

+0

謝謝,儘管你的'attachBitmap()'是錯誤的,因爲沒有參數提供實例名。 –

+0

@GeorgeReith對不起,我忘了在編輯你的代碼的時候刪除它。我現在編輯了代碼 – Moorthy