Copy link to clipboard
Copied
How do I put data from every XMLnode related,in separate movieclips when clicking a line in combobox?
A sample from the XML is like this:
<Planter>
<Lauvtre>
<Botanisk_navn>Acer campestre</Botanisk_navn>
<Norsk_navn>Naverlønn</Norsk_navn>
<Farge>Grønn</Farge>
<Herdighet>H4</Herdighet>
<Høyde>10-15 m</Høyde>
</Lauvtre>
I have a combobox where it shows the Botanical name, and the Norwegian name. But the rest of the info has to be shown in separate movieclips.
Anyone have an idea how to do this? Can I use the trace function maybe? Here is my AS3 code so far:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);
list.addEventListener(Event.CHANGE, itemChange);
function itemChange(e:Event):void
{
ta.text = list.selectedItem.data;
tb.text = list.selectedItem.label;
}
var xml:XML;
function onLoaded(e:Event):void
{
xml = new XML(e.target.data);
var il:XMLList = xml.Planter.Lauvtre;
for(var i:uint=0; i<il.length(); i++)
{
list.addItem({data:il.Farge.text() +"\n"+ il.Herdighet.text()+"\n"+ il.Høyde.text(),
label:il.Botanisk_navn.text() +"\n"+ il.Norsk_navn.text()});
}
}
loader.load(new URLRequest("lauvtre.xml"));
Thanks!
Rheus.
i'm not sure what you're trying to do. but, if you wanted to populate a combobox with botanical names and when one is selected, access the other names use:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);
list.addEventListener(Event.CHANGE, itemChange);
function itemChange(e:Event):void {
var selectedObj:Object = a[list.selectedIndex]
trace(selectedObj['Farge'],selectedObj['Botanisk'],etc);
}
var xml:XML;
var a:Array = [];
function onLoaded(e:Event):void
...Copy link to clipboard
Copied
if Planter is your root node, you should be using:
xml = new XML(e.target.data);
var il:XMLList = xml.Lauvtre;
to reference your data.
Copy link to clipboard
Copied
Hi! And thank you for helping. Planter is my root node. I tried removing "Planter" from xml.Planter.Lauvtre. It didn't fetch any data then. My code works as is, but what I want the code to do, is to put these 3:
<Farge>Grønn</Farge>
<Herdighet>H4</Herdighet>
<Høyde>10-15 m</Høyde>
...into separate textfields.
It has to be dynamic, so that when I click on one of the plant names in the combobox, the textfields get updated according to what is selected in the combobox.
I'm pretty new to Actionscript so I have a hard time explaining my problem:
I want to use the combobox as the menu, that has all the latin plant names listed. When I click on one of the 100 plantnames I want the correlating info from the XML, put in textfields.
Copy link to clipboard
Copied
then use:
function onLoaded(e:Event):void
{
xml = new XML(e.target.data);
var il:XMLList = xml.Planter.Lauvtre;
for(var i:uint=0; i<il.length(); i++)
{
tf1.text=il.child('Farge').toString();
etc
}
}
Copy link to clipboard
Copied
This may be a step along the way, however, it only shows the last node in the xml related to "Farge" in the text field, and it doesn't update when I click on a different name in the combobox.
Shouldn't it also be related to the itemChange function somehow?
list.addEventListener(Event.CHANGE, itemChange);
function itemChange(e:Event):void
{
ta.text = list.selectedItem.data;
tb.text = list.selectedItem.label;
}
Copy link to clipboard
Copied
i'm not sure what you're trying to do. but, if you wanted to populate a combobox with botanical names and when one is selected, access the other names use:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);
list.addEventListener(Event.CHANGE, itemChange);
function itemChange(e:Event):void {
var selectedObj:Object = a[list.selectedIndex]
trace(selectedObj['Farge'],selectedObj['Botanisk'],etc);
}
var xml:XML;
var a:Array = [];
function onLoaded(e:Event):void {
xml = new XML(e.target.data);
var il:XMLList = xml.Lauvtre;
for (var i:uint=0; i<il.length(); i++) {
list.addItem({label:il.child('Botanisk_navn').toString()});
a = {'Farge':il.child('Farge').toString(),'Herdighet':il.child('Herdighet').toString(),'Hoyde':il.child('Hoyde').toString(),'Botanisk':il.child('Botanisk_navn').toString(),'Norsk_navn':il.child('Norsk_navn').toString()};
}
}
loader.load(new URLRequest("test.xml"));
Copy link to clipboard
Copied
That was beautiful! After a little tinkering it worked!
THANK YOU SO MUCH!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now