1 Reply Latest reply on May 20, 2010 11:35 AM by oldMster

    Sending a KEY : VALUE variable pair to a HTTPSERVICE?

    mumcs01 Level 1

      So I"m working on sending a key and value to a PHP script. Simple. So below works if I define the KEY as a literal. (KEY1). But if I change the button publish to  <mx:Button label="Publish Changes" click="getConfig.send( { keytoinsert.text : valuetoinsert.text } )" , I get 'Expecting right paren before colon.' compiler error. Why can't I use a variable as a Key value to the left of the colon?

       

       

      --------------

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

      <mx:HTTPService id="getConfig" url="http://10.101.50.60/xmlpost.php"
      method="POST" showBusyCursor="true" resultFormat="e4x">
       
      </mx:HTTPService>
       
       
        <mx:FormItem label="Key:">
          <mx:TextInput id="keytoinsert" />
         </mx:FormItem>
         <mx:FormItem label="Value:">
          <mx:TextInput id="valuetoinsert" />
         </mx:FormItem>

      <mx:Button label="Publish Changes" click="getConfig.send( { KEY1 : valuetoinsert.text } )" />


      </mx:Application>

        • 1. Re: Sending a KEY : VALUE variable pair to a HTTPSERVICE?
          oldMster Level 3

          I don't think you can do it in the MXML declaration, but you can do it in a script:

           

          -----

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

          <mx:Script>

               <![CDATA[

                    private function sendit():void {

                         if (keytoinsert != NULL ) {

                              if (keytoinsert.text != "") {

                                   var params:Object = new Object();

                                   params[keytoinsert.text] = valuetoinsert.text;

                                   getConfig.send(params);

                              }

                         }

                    }

               ]]>

          </mx:Script>

           

           

           

          <mx:HTTPService id="getConfig" url="http://10.101.50.60/xmlpost.php"
          method="POST" showBusyCursor="true" resultFormat="e4x">
           
          </mx:HTTPService>
           
           
            <mx:FormItem label="Key:">
              <mx:TextInput id="keytoinsert" />
             </mx:FormItem>
             <mx:FormItem label="Value:">
              <mx:TextInput id="valuetoinsert" />
             </mx:FormItem>

          <mx:Button label="Publish Changes" click="sendit( );" />

           


          </mx:Application>