PDA

View Full Version : Populating empty array - php to Flash


snapple
07-21-2004, 06:24 PM
Hello,

I am building a drawing application where people can save their drawings and then other people can 'replay' them later on. Variables such as name, x, y,colour, alpha and pen thickness etc are stored in 6 separate arrays and sent to php and stored in 1 table in a mysql database - this is all working fine.

So far i have the names (sent from an input textfield in flash) being echoed in php from the database:

Andrew, James, Simon, Charlotte, Amy

What i would like to do is get these names back to flash in an array. What would be the best way of achieving this? I have tried (not successfully) sending an empty array, from flash, to php and populating it and then sending it back to flash.

So say i have the following actionscript:


var imageArray = new Array();

_root.saveCo.onRelease = function ()
{
imageSend = new LoadVars();
imageBack = new LoadVars();

imageSend.recData = imageArray;

//i have the (success) argument in flash - just not here.

imageSend.sendAndLoad("http://localhost/swftest.php", imageBack, "POST");
}


I am stuck as to how to send it (empty) to php > populate it and send it back to flash. I would really be very grateful for any help regarding this problem.

This is only one of my 'personal' projects (that appears to turn less fun everyday), so don't stress about time.

Thank you once again for your time and effort.

Best regards, snapple :)

freddycodes
07-21-2004, 07:30 PM
Data structures like arrays, are not compatible between in Flash and PHP natively. In short you cannot do what you are trying to do the way you are trying to do it.

You can however, use something like wddx or amf to convert the data into an array in its native format.

Or you can simply send the names back from the database using some sort of delimiter like a | or newline. Then you can split the data in flash to create your arrray.

snapple
07-21-2004, 11:07 PM
Thank you very much. I did not know that you could not pass data structures between Flash and php - i certainly will not forget that. I think i'll just pass the names back as a string, they are echoed just as a string now, using mysql_fetch_array().

Thank you very much freddycodes.

Best regards, snapple :)

RedMage
08-17-2004, 01:07 AM
I'd think it would be possible to send a PHP array to flash in URL format o flash and then have flash populate the array with the name value pairs. An example would be Something like this:

AS:

var myArray:Array = new Array();
// GET DATA
var arLink:LoadVars = new LoadVars();
arLink.load("http://somwhere.com/flashtest.php", POST);
arLink.onLoad = function (linkLoad) {
if(linkLoad) {
for (i = 0; i <= (arLink.sLen - 1); i++) {
myArray[i] = eval("arLink.theArray" + i);
}
}
}
// GET DATA


PHP

<?
$theArray = array ();
$theArray[0] = "One";
$theArray[1] = "Two";
$theArray[2] = "Three";

$sLen = count($theArray);
$aLen = 0;
echo "sLen=$sLen";
foreach($theArray as $current) {
echo "&theArray$aLen=" . $current ;
$aLen++;
}
?>


It may be a little rusty but I tested it and it does poplute the array with the appropriate values. I am currently using something similar to this to provide a dynamic playlist

CyanBlue
08-17-2004, 02:48 PM
Here is another interesting approach that can never come out of my brain... :D
It does look like one way communication from Flash to PHP but it looks like it will do the job just fine...

http://www.actionscript.org/forums/showthread.php3?t=52872