3 Replies Latest reply on Oct 23, 2009 8:17 PM by ZeKid

    Data comboBox

    RosieGp

      I have the follwoing:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        creationComplete="addRecord();" width="100%" height="100%">
        <mx:Script>
          <![CDATA[
            import mx.controls.*;

            private function addRecord():void{
              var vb:VBox = new VBox();
              vb.setStyle("backgroundColor", "0xFFFFFF");
              var infoLbl:Label = new Label();
              infoLbl.text="Information"
              infoLbl.setStyle("fontWeight", "bold");
              vb.addChild(infoLbl);
              var selectCbx:ComboBox = new ComboBox();
              selectCbx.prompt = "Make a Selection";

               ISSUE 1

              selectCbx.dataProvider="{rhdata}";
              vb.addChild(selectCbx);

              var selectCbx2:ComboBox= new ComboBox();

              selectCbx2.prompt = "New/Existing";

                ISSUE 2

              //// how to add an arraycollection here something like so that it display data in ComboBox

             ////  <mx:ArrayCollection> <mx:String>New</mx:String> <mx:String>Existing</mx:String> </mx:ArrayCollection>

             ////  OR can I do something like

             ////  var RHarray:Array = ["New", "Existing"];

              vb.addChild(selectCbx2);
              var partA_Lbl:Label = new Label();
              partA_Lbl.text = "Part A";
              partA_Lbl.setStyle("fontWeight", "bold");
              vb.addChild(partA_Lbl);
              var recordA_Rte:RichTextEditor = new RichTextEditor();
              recordA_Rte.title="Record A"
              recordA_Rte.height=249;
              recordA_Rte.width=454;
              vb.addChild(recordA_Rte);
              var recordB_Rte:RichTextEditor = new RichTextEditor();
              recordB_Rte.title="Record B"
              recordB_Rte.height=249;
              recordB_Rte.width=518;
              vb.addChild(recordB_Rte);
              var partB_Lbl:Label = new Label();
              partB_Lbl.text = "Part B";
              partB_Lbl.setStyle("fontWeight", "bold");
              vb.addChild(partB_Lbl);
              var hr:HRule = new HRule();
              hr.setStyle("strokeWidth", 2);
              hr.setStyle("strokeThickness", 2);
              hr.percentWidth = infoVB.width;
              infoVB.addChildAt(hr, 0);
              infoVB.addChildAt(vb, 0);
            }     
          ]]>
        </mx:Script>

      [Bindable] public var rhdata:ArrayCollection;

      private function resultNR(event:ResultEvent):Void{

          rhdata=ArrayCollection(event.result);

      }

      <mx:RemoteObject id="cf" destination="ColdFusion" source="cfc.CR">

       

      <mx:method name="getNR" result="resultNR(event)" fault="Alert.show(event.fault.message)"/>

       

       

      </mx:RemoteObject>

       

       

       

       

       

       

       


        <mx:Button x="878" y="625" label="Add New Record" click="addRecord();"/>
        <mx:VBox id="infoVB" verticalGap="15" horizontalAlign="center"/>
      </mx:Application>

       

      The issue 1 is when I run this, all I see in the combobox is {rhdata} as result... and nothing else. Please let me know if I'm missing anything.

      Thanks...

        • 1. Re: Data comboBox
          ZeKid

          Hello RosieGp,

           

          See modifications below ...  The syntax is a bit different in AS and mxml.

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

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

          <mx:Application

           

          xmlns:mx="http://www.adobe.com/2006/mxml"

          creationComplete="resultNR();addRecord();" width="

          100%" height="100%">

           

           

          <!--creationComplete="addRecord();" width="100%" height="100%">-->

           

           

           

           

           

           

          <mx:Script>

          <![CDATA[

           

           

          import

          mx.controls.*;

           

           

          import

          mx.collections.ArrayCollection;

           

           

           

          private function addRecord():void

          {

           

           

          var vb:VBox = new

          VBox();

          vb.setStyle(

           

          "backgroundColor", "0xFFFFFF"

          );

           

           

          var infoLbl:Label = new

          Label();

          infoLbl.text=

           

          "Information"

          infoLbl.setStyle(

           

          "fontWeight", "bold"

          );

          vb.addChild(infoLbl);

           

           

          var selectCbx:ComboBox = new

          ComboBox();

          selectCbx.prompt =

           

          "Make a Selection"

          ;

           

           

           

           

          //ISSUE 1

           

           

          //selectCbx.dataProvider="{rhdata}";

          selectCbx.dataProvider=rhdata;

           

           

           

          vb.addChild(selectCbx);

           

           

           

          var selectCbx2:ComboBox= new

          ComboBox();

           

          selectCbx2.prompt =

           

          "New/Existing"

          ;

           

           

           

           

          //ISSUE 2

           

           

          //// how to add an arraycollection here something like so that it display data in ComboBox

           

           

          //// <mx:ArrayCollection> <mx:String>New</mx:String> <mx:String>Existing</mx:String> </mx:ArrayCollection>

           

           

          //// OR can I do something like

           

           

          //// var RHarray:Array = ["New", "Existing"];

           

           

          var myArrayCollection:ArrayCollection = new ArrayCollection( [{label:'New'},{label:'Existing'}] );

          selectCbx2.dataProvider = myArrayCollection;

           

           

           

           

          vb.addChild(selectCbx2);

           

           

          var partA_Lbl:Label = new

          Label();

          partA_Lbl.text =

           

          "Part A"

          ;

          partA_Lbl.setStyle(

           

          "fontWeight", "bold"

          );

          vb.addChild(partA_Lbl);

           

           

          var recordA_Rte:RichTextEditor = new

          RichTextEditor();

          recordA_Rte.title=

           

          "Record A"

          recordA_Rte.height=249;

          recordA_Rte.width=454;

          vb.addChild(recordA_Rte);

           

           

          var recordB_Rte:RichTextEditor = new

          RichTextEditor();

          recordB_Rte.title=

           

          "Record B"

          recordB_Rte.height=249;

          recordB_Rte.width=518;

          vb.addChild(recordB_Rte);

           

           

          var partB_Lbl:Label = new

          Label();

          partB_Lbl.text =

           

          "Part B"

          ;

          partB_Lbl.setStyle(

           

          "fontWeight", "bold"

          );

          vb.addChild(partB_Lbl);

           

           

          var hr:HRule = new

          HRule();

          hr.setStyle(

           

          "strokeWidth"

          , 2);

          hr.setStyle(

           

          "strokeThickness"

          , 2);

          hr.percentWidth = infoVB.width;

          infoVB.addChildAt(hr, 0);

          infoVB.addChildAt(vb, 0);

          }

           

          [

           

          Bindable

          ]

           

           

          public var

          rhdata:ArrayCollection;

           

           

           

          /*private function resultNR(event:ResultEvent):void {

          rhdata=ArrayCollection(event.result);

          }*/

           

           

          // I don't have your cfc ...

          // Called from creationComplete ...

           

           

          private function resultNR():void

          {

          rhdata =

           

          new ArrayCollection( [{label:'2009-10'},{label:'2010-11'},{label:'2011-12'

          }] );

          }

           

          ]]>

           

           

          </mx:Script>

           

            

            

            

           

           

          <!--<mx:RemoteObject id="cf" destination="ColdFusion" source="cfc.CR">

          <mx:method name="getNR" result="resultNR(event)" fault="Alert.show(event.fault.message)"/>

          </mx:RemoteObject>-->

           

           

           

          <mx:Button x="878" y="625" label="Add New Record" click="addRecord();"/>

           

           

          <mx:VBox id="infoVB" verticalGap="15" horizontalAlign="center"

          />

           

          </mx:Application>

          1 person found this helpful
          • 2. Re: Data comboBox
            RosieGp Level 1

            //ISSUE 1

             

             

            //selectCbx.dataProvider="{rhdata}";

            selectCbx.dataProvider=rhdata;

             

            this is still not working....

            • 3. Re: Data comboBox
              ZeKid Level 1

              Hello Rosie,

               

              If the line:   selectCbx.dataProvider = rhdata;   is not working, my guess would be that it's your remote call that is not working.  But I really don't know, you have to be more specific ...

               

              If you copy and paste the code of my previous post into a new project and compile it, you'll see that it's working ...  but I'm not using the result of a remote call as the dataProvider for the comboBox ...  which is why I think it could be the remote call ...

               

              By the way, in your original code, there is no place where you actually call your remoteCall method getNR ...   i.e.    cf.getNR();

              I'm not sure if your "Make a Selection" comboBox must contains the same values for all the records that you add, but if it's the case, you only have to call your remote call once, at the beginning.

               

              Remote calls are asynchronous, which means you must wait for the results before continuing the processing, unless that processing has nothing to do with the result of the remote call.  In your case, you can not create your 1st record until you've received the result of your remoteCall, because you need it to fill up the comboBox in the records.  So instead of calling addRecord() from creationComplete(), I would call the remoteCall  cf.getNR() , and then, inside resultNR() , right after you've received rhdata , you would create the first record by calling addRecord().

               

              Also, note that in order to be able to compile your code, I had to move the following bit of code inside the </mx:Script> tag and rename "Void" to "void".

              [Bindable] public var rhdata:ArrayCollection;

              private function resultNR(event:ResultEvent):Void{

                  rhdata=ArrayCollection(event.result);

              }

               

              Let me know how it's going ...

              1 person found this helpful