...

View Full Version : Sending a matrix from PHP to AS3...



SuperDoD
04-22-2012, 10:30 PM
Hello!
I have a bit of a problem. I need to send a two dimensional array from PHP to AS3 and save the data in AS3 in a two dimensional array, but I can't find a way. Here is my code:

adatatvitel.php

<?php

require("db.php");

$sql = "SELECT * FROM kerdesvalasz";
$result = mysql_query($sql) or die(mysql_error());

$adatok = array
(
"kerdes" => array
(
),
"valasz1" => array
(
),
"valasz2" => array
(
),
"valasz3" => array
(
),
"valasz4" => array
(
),
"helyes" => array
(
)
);

$i=0;
while($row = mysql_fetch_array($result))
{
$adatok['kerdes'][$i] = $row ['kerdes'];
$adatok['valasz1'][$i] = $row ['valasz1'];
$adatok['valasz2'][$i] = $row ['valasz2'];
$adatok['valasz3'][$i] = $row ['valasz3'];
$adatok['valasz4'][$i] = $row ['valasz4'];
$adatok['helyes'][$i] = $row ['helyes'];
$i++;
}

for($i=0;$i<17;$i++)
{
echo "adatok=".$adatok['kerdes'][$i];
$temp = $_POST['adatok'];
if($temp == $adatok['kerdes'][$i])
{
ob_clean(); //clrscr();
}
}

?>

I just want to send the adatok[kerdes][$i] elements of the array first.


stop();

var loader:URLLoader=new URLLoader();
loader.dataFormat=URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE,onComplete)

function sendIt(e:MouseEvent):void
{
var request:URLRequest=new URLRequest("login.php");
request.method=URLRequestMethod.POST;
var vars:URLVariables=new URLVariables();
vars.user=user_txt.text;
request.data=vars;
loader.load(request);
}

function onComplete(e:Event):void
{
var request:URLRequest=new URLRequest("login.php");
request.method=URLRequestMethod.POST;
var loader:URLLoader=URLLoader(e.target);
var vars:URLVariables=new URLVariables(loader.data);
gotoAndStop(2);
uzenet.text=vars.user;
}

login_btn.addEventListener(MouseEvent.CLICK,sendIt);
start_btn.addEventListener(MouseEvent.CLICK,startquiz);

var adatok:Array = [];
var valtozo:String = new String();
var i:int = 0;
var j:int = 0;
var szamlalo:int = 0;

for(i=0;i<17;i++)
{
adatok[i] = [];
}
i=j=0;

function startquiz(e:MouseEvent):void
{
var request:URLRequest=new URLRequest("adatatvitel.php");
request.method=URLRequestMethod.POST;
var loader:URLLoader=URLLoader(e.target);
while(szamlalo<17)
{
var vars:URLVariables=new URLVariables(loader.data);
adatok[i][j] = vars.adatok;
request.data = vars.adatok;
j++;
szamlalo++;
}
gotoAndStop(3);
}

MarPlo
04-23-2012, 06:34 PM
Hi,
When transfering data from php to another aplication, it is indicated to use JSON format.
In your case, you can store into an array the data you want to send to AS3, then use json_encode() and output the json string.


$arrtosend = array();
while(...) {
...
$arrtosend[] = $row ['valasz1'];
}

echo json_encode($arrtosend);

In AS3 you can convert the json string back into an object /array, but i don't know the function for AS3.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum