My XML looks as follows
<?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>
In my folder I have the XML as shown. There are 6 images in the folder and the names are given as urls. I have a combo box on stage. Its name myCB. There is an image holder imgHolder_mc.
I have two tasks.
Populate the combo box with the imageNames.
Based on the imageName selected the image in the image holder must change. The image must be retrieved using the image url.
This is what I have did so far
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);
}
The trace gives me
<imgName>"Angelina Jolie"</imgName>
<imgName>"Big B"</imgName>
<imgName>"Brad Pitt"</imgName>
<imgName>"Mohanlal"</imgName>
<imgName>"Prithviraj"</imgName>
<imgName>"Tom Cruise"</imgName>
Please advice me as how I can bind this to my combo box and select images according to the selection I made in combo box.
1 Answer