0
我的XML看起來如下加載數據從XML組合框
<?xml version="1.0" encoding="utf-8"?>
<Images>
<Image imgID = "1" >
<imgName>"Angelina Jolie"</imgName>
<url>"Angelina Jolie.jpg"</url>
</Image>
<Image imgID = "2" >
<imgName>"Big B"</imgName>
<url>"Big B.jpg"</url>
</Image>
<Image imgID = "3" >
<imgName>"Brad Pitt"</imgName>
<url>"Brad Pitt.jpg"</url>
</Image>
<Image imgID = "4" >
<imgName>"Mohanlal"</imgName>
<url>"Mohanlal.jpg"</url>
</Image>
<Image imgID = "5" >
<imgName>"Prithviraj"</imgName>
<url>"Prithviraj.jpg"</url>
</Image>
<Image imgID = "6" >
<imgName>"Tom Cruise"</imgName>
<url>"Tom Cruise.jpg"</url>
</Image>
</Images>
在我的文件夾我有XML,如圖所示。該文件夾中有6個圖像,名稱以urls的形式給出。我在舞臺上有一個組合框。它的名字是myCB。有一個圖像保持器imgHolder_mc。
我有兩個任務。
使用imageNames填充組合框。
根據選擇的圖像名稱,圖像保持器中的圖像必須更改。必須使用圖片網址來檢索圖片。
這是我做過到目前爲止
import fl.data.DataProvider;
myCB.prompt = "Select Image:";
var model_dp:DataProvider = new DataProvider(xmlData);
myCB.dataProvider = model_dp;
// Creates the variable(s) to load the XML externally
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
// Ensuring that we do not prematurely start fiddling with the XML data until all of our data has been loaded
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
// We call our xmlLoader's load method
xmlLoader.load(new URLRequest("Images.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
trace(xmlData..imgName);
}
跟蹤給我
<imgName>"Angelina Jolie"</imgName>
<imgName>"Big B"</imgName>
<imgName>"Brad Pitt"</imgName>
<imgName>"Mohanlal"</imgName>
<imgName>"Prithviraj"</imgName>
<imgName>"Tom Cruise"</imgName>
請根據選擇諮詢我,我怎麼能結合這我的組合框,然後選擇圖片我在組合框中製作。
您需要從組件面板中拖出一個'comboBox'並將其命名爲「myCB」。 – Benny