1 Reply Latest reply: Jan 14, 2013 6:31 PM by Ned Murphy RSS

    Adding list data into a TextArea trouble.

    Kristtee Community Member

      Hi

      I have loaded xml data into a tile list and added event listener to capture clicks. When I click an item in TileList, i intend to add the item label into a TextArea. All goes well. Yet, the problem is item label gets updated instead of appended to the TextArea. I hope it can be fixed. Any help would be appreciated.

      Thank you

      Kristtee

       

      ---------- Here is the code and xml-----------------

      <?xml version="1.0" encoding="UTF-8"?>

      <lib>

                <itm name="One" sos="images/1.png" />

                <itm name="Two" sos="images/2.png" />

                <itm name="Three" sos="images/3.png" />

                <itm name="Four" sos="images/4.png" />

                <itm name="Five" sos="images/5.png" />

      </lib>

       

      AS3 Code

      -----------

      import flash.net.URLLoader;

      import flash.events.Event;

      import flash.net.URLRequest;

       

       

      var xmlData:XML;

      var path:String = "tlData.xml";

      var loader:URLLoader = new URLLoader();

      loader.addEventListener(Event.COMPLETE, dataLoaded);

      loader.load(new URLRequest(path));

       

       

      function dataLoaded(e:Event):void{

                System.disposeXML(xmlData);

                xmlData = new XML(e.target.data);

                for(var i:int = 0; i<xmlData.itm.length(); i++){

                          //trace(xmlData.itm[i].@name);

                          myTL.addItem({label:xmlData.itm[i].@name, source:xmlData.itm[i].@sos});

                }

                myTL.addEventListener(Event.CHANGE, ecHandler);

                myTL.selectedIndex = 0;

      }

      function ecHandler(event:Event):void{

                //trace(myTL.selectedItem.label);

                myTa.text = myTL.selectedItem.label;

      }

        • 1. Re: Adding list data into a TextArea trouble.
          Ned Murphy CommunityMVP

          It isnot clear to me what you mean when you say the item label gets updated rather than appended to the TextArea.  Based on the code you show the TExtArea text will be reassigned whatever new label value is selected. 

           

          If you want to append the text so that each label adds to the next, then try using the appendText() method...

           

          myTa.appendText(myTL.selectedItem.label);

           

          You might or might not want to add a line return ("\n") along with that.