3 Replies Latest reply on Nov 7, 2009 4:41 AM by Shivik

    Populate ComboBox from RemoteObject data

    Shivik

      Hello all

       

      I am trying to use RemoteObject for populating a combobox. Here's my value object and mxml code....

      // Value Object Class: dataVO.as
      package com.mycomp
      {
           [RemoteClass(alias="datavO")]
           [Bindable]
           public class dataVO {
                public var data_id:int;
                public var data_name:String;
                public var data_type:String;
           }
      }
      
      // ActionScript code
      private
      function getAuthors(event:Event):void
      {
           // setup the remoteobject here

           serviceRO.getData.addEventListener(ResultEvent.RESULT, resultListener);
      }
      private function resultListener(event:Event):void
      {
           dgrid1.dataProvider = event.result as Array; // works perfectly
           combo1.dataProvider = event.result.data_name as Array; // displays empty combobox
      }

      <!-- MXML Code -->
      <mx:ComboBox id="combo1" /> <!-- I want to populate names here -->
      <mx:DataGrid id="dgrid1" />

       

      How should I do this?

       

      Thanks and Regards

      ShiVik

        • 1. Re: Populate ComboBox from RemoteObject data
          Shivik Level 1

          I am happy for now. I found out that this can be done by using the property labelField

           

          // ActionScript code
          private
          function getAuthors(event:Event):void
          {
               // setup the remoteobject here

               serviceRO.getData.addEventListener(ResultEvent.RESULT, resultListener);
          }
          private function resultListener(event:Event):void
          {
               dgrid1.dataProvider = event.result as Array; // works perfectly
               combo1.dataProvider = event.result;
               combo1.labelField = "data_name";
          }

          <!-- MXML Code -->
          <mx:ComboBox id="combo1" /> <!-- I want to populate names here -->
          <mx:DataGrid id="dgrid1" />

           

          What about the dataField however? What if I want to setup some event on the selection of comboBox, which I will have to eventually.

          • 2. Re: Populate ComboBox from RemoteObject data
            salem_b_a

            Hi,

             

            i faced this problem somewhere, all i remember is that the array of variables was saved on the event.result[0].

            i didn't really understand why, but that worked for me.

            you may try event.result[0].data_name

             

            else you will have to run throught the result manually, and make your own data_name array.

             

            Try to debug and see the result structure.

             

            Hope this helps,

            Salem

            • 3. Re: Populate ComboBox from RemoteObject data
              Shivik Level 1

              Yes Salem.You are right.

               

              salem_b_a wrote:

               

              i faced this problem somewhere, all i remember is that the array of variables was saved on the event.result[0].

              i didn't really understand why, but that worked for me.

              you may try event.result[0].data_name

              Indeed that's what I also found while trying to use the selectedItem property. It displays the RemoteObject for that particular row.

               

              I made use of the same to get what I wanted....

              private function onChange(event:ListEvent):void {
                   Alert.show(combo1.selectedItem.data_name);
              }
              

               

              Thanks and Regards

              ShiVik