views:

127

answers:

2

I am Using Flex 3 and apache with PHP 5.2.

I am searching for simple as possible way to fill my mx:List with data using POST URLRequest.

In Flex builder I am using the next code

public var variables_se:URLVariables = new URLVariables();
public var varSend_se:URLRequest = new URLRequest("DataProvider.php");
public var varLoader_se:URLLoader = new URLLoader;

public function starter():void
{
varSend_se.method = URLRequestMethod.POST;
varSend_se.data = variables_se;
varLoader_se.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader_se.addEventListener(Event.COMPLETE, completeHandler_se);
variables_se.CountOflistItemsIWant = 30;
varLoader_se.load(varSend_se);
}

public function completeHandler_se(event:Event):void
{
    textFild.text += " " + String(event.target.data) + ";"; // any result will apear in some textFild
// How to make result appear as list lines, how to form PHP answer and AS3 code for it?
}

How to make result appear as list lines, how to form PHP answer and AS3 code for it (If for example I want to return random numbers from PHP in desired in CountOflistItemsIWant cuatety)?

A: 

Maybe you could make your php script echo json encoded array like so:

<?php
echo json_encode(array('first', 'second', 'foo', 'bar'));

and in flex get it, decode it and use it as argument for array data provider for your mx:List

You can find information about communicating between php and flex with use of json here: http://www.adobe.com/devnet/flex/articles/flex_php_json.html

Kamil Szot
A: 

IMHO this is a larger architectural question. Here are the options:

  1. Create a RESTful web service and have it output data in some text format (XML or JSON). You can use the HttpService objects in Flex to make request to your PHP restful web service and set result and fault handlers accordingly. Here's the quick start: http://www.adobe.com/devnet/flex/quickstart/httpservice/

  2. If you need to remote objects directly between Flex and PHP, AMFPHP can be used: http://www.amfphp.org/

  3. You can create a SOAP web service in PHP, some references... http://developer.apple.com/internet/webservices/soapphp.html http://php.net/manual/en/book.soap.php ... and use the Flex WebService object to make calls: http://livedocs.adobe.com/flex/3/html/data_access_3.html

Srirangan