Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I put data from every XMLnode related,in separate movieclips when clicking a line in combobox

New Here ,
Jun 08, 2013 Jun 08, 2013

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.

TOPICS
ActionScript
972
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 09, 2013 Jun 09, 2013

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

...
Translate
Community Expert ,
Jun 09, 2013 Jun 09, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 09, 2013 Jun 09, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2013 Jun 09, 2013

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

                    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 09, 2013 Jun 09, 2013

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2013 Jun 09, 2013

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"));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 10, 2013 Jun 10, 2013

That was beautiful! After a little tinkering it worked!

THANK YOU SO MUCH!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 10, 2013 Jun 10, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines