Expand my Community achievements bar.

SOLVED

Adobe httpservice question

Avatar

Level 2

Hello,

      I have couple of questions on httpservice and combobox.

1. I have a array collection of value objects, I want to send the data in these value objects over httpservices. My code for httpservice is:

<mx:HTTPService

id="createAccount" url="http://localhost/createAccount.php" method="POST" result="accountResult(event)">

<mx:request xmlns="">

<usernames>

</usernames>

</mx:request>

</mx:HTTPService>

If the data is directly from controls its not a problem but if its from a value object how do i send the data in actionscripts??.

2. I want to know how to populate the combobox dynamically.. for example, when I press a button, i want to populate the combobox with a text retrieved from an edit box and i want to select that item. I checked combobox class, it doesnt have additem funcion in it..

Any help would be appreciated.

Thanks,

Bharani

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

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

1) Maybe just send the data using myVO.toString(), or else use JSON to encode the data. These links may help:

http://www.switchonthecode.com/tutorials/flex-php-tutorial-transmitting-data-using-json

http://www.switchonthecode.com/tutorials/using-flex-php-and-json-to-modify-a-mysql-database

http://www.switchonthecode.com/tutorials/flex-php-json-mysql-advanced-updating

2) Add to the ComboBox dataProvider. With data driver controls, you almost always want to operate on the dataProvider to affect what appears in the control.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script>
    <![CDATA[
      import mx.collections.ArrayCollection;
      [Bindable] private var ac:ArrayCollection = new ArrayCollection([
        "one", "two", "three"
      ]);
     
      private function clickFunc():void{
        if(txt.text != ""){
          ac.addItemAt(txt.text, 0);
          cbx.selectedIndex=0;
        }
      }
    ]]>
  </mx:Script>
  <mx:ComboBox id="cbx" dataProvider="{ac}"/>
  <mx:TextInput id="txt"/>
  <mx:Button label="Add Item" click="clickFunc()"/>
</mx:Application>

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

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

1) Maybe just send the data using myVO.toString(), or else use JSON to encode the data. These links may help:

http://www.switchonthecode.com/tutorials/flex-php-tutorial-transmitting-data-using-json

http://www.switchonthecode.com/tutorials/using-flex-php-and-json-to-modify-a-mysql-database

http://www.switchonthecode.com/tutorials/flex-php-json-mysql-advanced-updating

2) Add to the ComboBox dataProvider. With data driver controls, you almost always want to operate on the dataProvider to affect what appears in the control.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script>
    <![CDATA[
      import mx.collections.ArrayCollection;
      [Bindable] private var ac:ArrayCollection = new ArrayCollection([
        "one", "two", "three"
      ]);
     
      private function clickFunc():void{
        if(txt.text != ""){
          ac.addItemAt(txt.text, 0);
          cbx.selectedIndex=0;
        }
      }
    ]]>
  </mx:Script>
  <mx:ComboBox id="cbx" dataProvider="{ac}"/>
  <mx:TextInput id="txt"/>
  <mx:Button label="Add Item" click="clickFunc()"/>
</mx:Application>

Avatar

Level 2

Thanks for your reply.. it was very helpful.. I have a question again.. my question was to send data in value objects to the server. So here is my code

private function CreateAccount():

void

{

var httpConn:HTTPService = new HTTPService("http://localhost/createAccount.php"

);

httpConn.request.fullname = FullNameEdit.text;

httpConn.request.numusers = userList.length;

for(var i:Number = 0; i < userList.length; i++)

{

var user:UserDetails = userList[i];

httpConn.request.username[i] = user.userName;

}

httpConn.send();

What I want is the event that is sent when the post is sent and a reply comes back from the webserver. I wanna do this from the actionscript. is there a way to do it??

Thanks,

Bharani

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----