3 Replies Latest reply on Dec 30, 2009 7:59 PM by Gregory Lafrance

    entirearray collection to textbox

    miguel8312 Level 3

      Hello guys

       

      I'm getting an array collection from a webservice however what i would like to do is not just get 1 of the items of the array and passed it to text i've been able to figuered this one out. instead i would like to take the entire arraycollection and put its text value into a textInput box. does anyone have an example how to do this im extremely frustudated trying to do this?...

       

      TO ADOBE:

      this forums should have CODE TAGS!!! why dont we add those :-)

       

      thanks

      MIguel

       

      some code

       

      my functions

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

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:fc="http://www.adobe.com/2006/fc" creationComplete="initApp()">

       

       

       

      <mx:Script>

      <![CDATA[

       

      import mx.controls.Alert;

       

      import mx.rpc.events.FaultEvent;

       

      import mx.rpc.events.ResultEvent;

       

      import mx.controls.Text;

       

      import mx.collections.ArrayCollection;

      [

      Bindable]

       

      public var myData:ArrayCollection;

       

       

      public function initApp():void {

       

      trace("hello11111");

      ws.GetEmployees(AC.text);

       

      }

       

       

      private function GetEmployees(event:ResultEvent):void {

      datagrid.dataProvider = event.result;

      myData = event.result

      as ArrayCollection;

       

      trace("hello");

      }

       

      private function fault(event:FaultEvent):void {

       

      // Oppps some error occured

      Alert.show(event.toString());

       

      trace("hello");

      }

       

       

      private function AddRecord(event:MouseEvent):void {

       

      // Save a record using a WebService method

       

      //ws.SaveEmployee(txtEmpId.text, txtEmpName.text, txtEmpEmail.text); //

      }

       

       

       

      ]]>

      </mx:Script>

       

       

       

       

       

       

       

       

       

       

      this is my input box

      <mx:VBox>

       

       

      <mx:HBox>

       

       

      <fc:AutoComplete id="AC" dataProvider="{myData.getItemAt(1-4).spriden_id}" text="{}" labelField="name"/>

       

       

      <mx:VBox width="250">

       

       

       

      </mx:VBox>

       

      </mx:HBox>

       

       

      <mx:Text text="Source:"/>

       

       

      <mx:TextInput id="AC2" text="{myData.getItemAt(0).spriden_id}" />

       

       

      <mx:Text htmlText="{}" color="#0033CC"/>

       

       

      </mx:VBox>

       

        • 1. Re: entirearray collection to textbox
          Gregory Lafrance Level 6

          This should wor for you:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            creationComplete="init();">
            <mx:Script>
              <![CDATA[
                import mx.collections.ArrayCollection;
                private var ac:ArrayCollection = new ArrayCollection(["These", "are", "words."]);
                
                private function init():void{
                  txt.text = ac.toArray().toString().replace(/,/g, " ");
                }
              ]]>
            </mx:Script>
            <mx:TextInput id="txt"/>
          </mx:Application>
          


          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified
          www.ChikaraDev.com
          Flex / AIR Development, Training, and Support Services

          • 2. Re: entirearray collection to textbox
            miguel8312 Level 3

            Greg thanks for your answer this is awesome.

             

            Just one more question. If i have this arraay collection as a bindable

             

             

             

             

            [Bindable]

             

            public var myData:ArrayCollection;

             

            and on my text i have this 

             

             

            <mx:TextInput id="AC2" text="{myData.toArray().toString()}" />

             

             

             

             

             

             

             

             

             

            i get this  when [object], [object]

            whats the difference?  it does not work?

             

             

             

             

             

             

             

            I get nothing when i do it like this...

             

            function GetEmployees(event:ResultEvent):void {


            datagrid.dataProvider = event.result;

            myData = event.result as ArrayCollection;

            AC.text = myData.toArray().toString();

             

             

             

            trace("hello");

             

             

             

             

            Thanks again

            Miguel

             

             

             

             

            • 3. Re: entirearray collection to textbox
              Gregory Lafrance Level 6

              My code will only work if the ArrayCollection contains things like strings, numbers, etc.

               

              If it contains objects, you may need more complex code, like looping through the ArrayCollection and printing its fields.