2011-12-10 35 views
1

我正在拉一個xml文件,其中只有一個結果。其中一個節點是圖片,其中包含指向圖片的鏈接。這是xml文件:設置圖像組件的來源不起作用

<artist> 
    <id>502</id> 
    <name>Bad Religion</name> 
    <picture>http://userserve-ak.last.fm/serve/500/46612615/Bad Religion BR 2010.jpg</picture> 
    <twitter></twitter> 
</artist> 

我測試了網址,它是正確的。這是我如何嘗試將url綁定到圖像實例(artistPic),但它不起作用。顯示藝術家名字確實有效。

var artist:XMLList = new XMLList(event.result); 
artistPic.source = artist.picture; 
lblArtistName.text = artist.name; 
+0

我想我以前說過:「它不工作」,說什麼是錯的。除非您提供更多信息,否則即使不是不可能,也很難幫助您。爲了讓您和其他人更容易,您可以使用Flash Player內容調試器插件(只需Google找到它),您可以顯示任何錯誤消息,可以跟蹤東西以查看變量未正確設置的位置,以及你至少應該提供給artistPic的代碼。 – weltraumpirat

回答

2

這是因爲artist.picture返回一個XMLList對象。嘗試下面的代碼:

var artist:XML = new XML(event.result); 
artistPic.source = String(artist.picture[0]); 
lblArtistName.text = artist.name; // This one is probably transtyped automagically by Flex.