stevethomas
11-04-2009, 10:21 PM
I have an xml that populates a combo box on the stage (instance name of ddList). It works okay, but when I choose an item from the dropdown and then go for another, the combo box gets populated again. So, if I have 4 items to start with, the next time I go to choose I have 8, then 12, etc.
Here is the code I have which I gleened from various tutorials/examples (which I'm sure is the problem considering I really don't know what I'm doing.)
Any help would be appreciated. And if you know of some code that is less extensive and gets the same job done, please post.
import fl.controls.ComboBox;
import fl.data.DataProvider;
ddList.width = 125;
ddList.prompt = "Counties";
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("mn_counties.xml"));
xmlLoader.addEventListener(Event.COMPLETE, getXML);
var xml:XML;
var county:Array = new Array();
var objects_array=new Array();
ddList.addEventListener(Event.CHANGE, getCounties);
ddList.addEventListener(Event.CHANGE, getInfo);
function getXML(e:Event):void
{
xml = new XML(e.target.data);
var il:XMLList = xml.county;
for(var i:uint=0;i<il.length();i++)
{
county[i] = new Array(il.@name[i],il.@data[i]);
for(var x:uint=0;x<il[i].county.length();x++)
{
county[i].push(il[i].county[x]);
}
}
getCounties();
}
function getCounties(e:Event = null):void
{
for(var i:int=0;i<county.length;i++)
{
ddList.addItem({label:county[i][0],data:county[i][1]});
}
}
Here is my xml
<?xml version="1.0" encoding="utf-8"?>
<counties>
<county name="Aitkin" data="item1"/>
<county name="Anoka" data="item2"/>
<county name="Becker" data="item3"/>
<county name="Beltrami" data="item4"/>
</counties>
Second part of my question is how to populate a text box with info from the same xml by clicking on an item from the dropdown list. This is what I have so far (which doesn't work, of course)
function getInfo(event:Event):void
{
name_txt.text = xml.county.name.text();
client_txt.text = xml.county.data.text();
}
THANKS!
Here is the code I have which I gleened from various tutorials/examples (which I'm sure is the problem considering I really don't know what I'm doing.)
Any help would be appreciated. And if you know of some code that is less extensive and gets the same job done, please post.
import fl.controls.ComboBox;
import fl.data.DataProvider;
ddList.width = 125;
ddList.prompt = "Counties";
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("mn_counties.xml"));
xmlLoader.addEventListener(Event.COMPLETE, getXML);
var xml:XML;
var county:Array = new Array();
var objects_array=new Array();
ddList.addEventListener(Event.CHANGE, getCounties);
ddList.addEventListener(Event.CHANGE, getInfo);
function getXML(e:Event):void
{
xml = new XML(e.target.data);
var il:XMLList = xml.county;
for(var i:uint=0;i<il.length();i++)
{
county[i] = new Array(il.@name[i],il.@data[i]);
for(var x:uint=0;x<il[i].county.length();x++)
{
county[i].push(il[i].county[x]);
}
}
getCounties();
}
function getCounties(e:Event = null):void
{
for(var i:int=0;i<county.length;i++)
{
ddList.addItem({label:county[i][0],data:county[i][1]});
}
}
Here is my xml
<?xml version="1.0" encoding="utf-8"?>
<counties>
<county name="Aitkin" data="item1"/>
<county name="Anoka" data="item2"/>
<county name="Becker" data="item3"/>
<county name="Beltrami" data="item4"/>
</counties>
Second part of my question is how to populate a text box with info from the same xml by clicking on an item from the dropdown list. This is what I have so far (which doesn't work, of course)
function getInfo(event:Event):void
{
name_txt.text = xml.county.name.text();
client_txt.text = xml.county.data.text();
}
THANKS!