Hey guys
Im a bit of a novice with flash and have become stuck while trying to achieve what should be a simple task.
I am trying to read in XML data and display the lables in a combo box and then display the corresponding data in a text field below. So that when for example “Vintage Red Wine” is selected in the combo box, the description for that wine will then be shown in the textfield below.
Most of the code is functional. The combo box displays the information i want. The only thing that doesnt want to work is the text field which should show the wine decriptions.
I would greatly appreciate if anyone could offer some help or advice.
Many Thanks
CPT_Crazy
Here is my XML data:
<?xml version=“1.0” encoding=“utf-8”?>
<Wines>
<Wine Price=“ö.99”>
<winename>Vintage Red</winename>
<description>A fairly good red wine</description>
</Wine>
<Wine Price=“ø.99”>
<winename>Awesome Red</winename>
<description>An awesome red wine</description>
</Wine>
<Wine Price=“ù.99”>
<winename>King Red</winename>
<description>The best there is!</description>
</Wine>
</Wines>
And the Action script:
stop();
import fl.events.ComponentEvent;
import fl.data.DataProvider;
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var myDP = new DataProvider();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest(“Wines.xml”));
//Edit Font style
var tf:TextFormat = new TextFormat();
tf.font = “Arial”;
tf.size = 12;
tf.bold = true;
myDP.setRendererStyle(“textFormat”, tf);
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
xmlData.ignoreWhite = true;
ParseWine(xmlData);
}
//Prints in output to show the data is coming in
function ParseWine(wineInput:XML):void {
trace(“XML Output”);
trace("------------------------");
var winenameList:XMLList = wineInput.Wine.winename;
for each (var winenameElement:XML in winenameList) {
trace(winenameElement);
}
for(var i:int = 0; i < winenameList.length(); i++)
{
//Populates the data provider with the xml data
myDP.addItem ( {label: winenameList*, data: winenameList*.attribute(“winename”)});
trace(myDP.getItemAt(i).label);
trace(myDP.getItemAt(i).data);
}
//Poupulates combobox (aCB) with the data added to the data provider in
//the previous step
aCB.dataProvider = myDP;
myDP.addEventListener(Event.CHANGE, showData);
function showData(event:Event) {
myTXT.text = event.target.selectedItem.attribute(“description”);
}
}