如何将AS3中的数组传递给php中的数组?

时间:2010-03-11 05:47:47

标签: flex actionscript-3 arrays

我有以下数组作为示例:

var arrayDefinitionsargsAmfPhp:Array = new Array();
arrayDefinitionsargsAmfPhp['tabela'] = "controls";
arrayDefinitionsargsAmfPhp['width'] = "100";

将他发送到远程对象的php,例如:

async = bridge.getOperation(amfphpFunction).send(arrayDefinitionsargsAmfPhp);

在php中我尝试得到这样的数组:

function retornamenu($tableInBd)
{

$arr = array($tableInBd);

$tableInBdname = $arr['tabela'];

$widthInBdname = $arr['width'];

但遗憾的是这些变量$ tableInBdname和$ widthInBdname都没有来到php,有人可以帮我一个例子吗?

谢谢

3 个答案:

答案 0 :(得分:0)

您可以通过提交URL变量/ ..

来发送
var variables:URLVariables = new URLVariables();
variables.NAME = "Hello";
variables.EMAIL = "Hello@Hello.com"

var request:URLRequest = new URLRequest("sentFromFlex.php");
request.data = variables;
request.method = URLRequestMethod.POST;
sendToURL(urlrequest);

在PHP中,您可以在$ _POST数组中获取这些变量..

echo $_POST['NAME'];
echo $_POST['EMAIL'];

答案 1 :(得分:0)

[Bindable] public var rows2:Object = new Object();

保存rows2 Object中的所有数据并将其发送给PHP。

rows2=Application.application.whateverStuff;

<mate:eventProperties>
<mate:EventProperties rows2="{rows2}"/>  
</mate:eventProperties>

现在,在Event属性中,您将获得rows2,并通过Remoting发送给PHP。

    public function yourPHP($data)
     {
     //return print_r($data,true); 
     if(!$data || !is_array($data)|| !sizeof($data)){throw new Exception("No data sent.".(is_object($data)?"y":"n"));}
     //throw new Exception(print_r($data,true));
     array_shift($data);//get rid of the first row
     foreach($data as $row)
     {
           Now perform your manipulation here.

        }
}

答案 2 :(得分:0)

答案还可以,解决方法是:

PHP

    function retornamenu($tableInBd)
{ 

$tableInBdname = $tableInBd['tabela'];

$mensagem = $tableInBd['mensagem'];

AS3

var arrayDefinitionsargsAmfPhp:Array = new Array();
arrayDefinitionsargsAmfPhp['tabela'] = "controls";
    arrayDefinitionsargsAmfPhp['mensagem'] = "este sao dados que vierem via array do as3";

async = bridge.getOperation(amfphpFunction).send(arrayDefinitionsargsAmfPhp);

感谢