PDA

View Full Version : passing arrays from php to flash


boyzdynasty
04-17-2003, 09:08 PM
in my flash file...
I have

Employee = new Array();

// then i call a script...


...i'm using register_globals 'ON'...if there is an easier or better let me know.

in my PHP script


<?php

/* Performing SQL query */
$query = "SELECT firstName, lastName FROM my_table";
$result = mysql_query($query) or die("Query failed");

/* I should be only two columns...but just make sure */
$col = mysql_num_fileds($result);

$i = 0;
while( $line = mysql_fetch_array($result){

for($j=0; $j < $col; $j++){
$Employee[$i][$j] = $line[$j];
}
$i++;
}
?>


It is not working.
In flash...when a trace is done to see if values were stored in the array Employee....
*nothing*

Any ideas...or am I just totally way off.

freddycodes
04-17-2003, 09:57 PM
How are you trying to get the array into Flash? Remoting? LoadVars() you'll need to be a bit more specific.

boyzdynasty
04-17-2003, 11:26 PM
what I used to call the script...

loadVariables("array_test.php", this, "POST");

Since global register is ON... the Emplyee Array is global?
so whatever I do to it in the php file...it will effect what is in the *swf, right?

freddycodes
04-17-2003, 11:29 PM
No, No and No. register gloabls in PHP has nothing to do with flash and actionscript, only with accessing variables send to the PHP script.

You cannot pass native PHP data types to flash and expect flash to recognize them. You need to serialize them somehow. Either XML or Remoting. Look at jesse's tutorial on AMFPHP or my tutorial on WDDX or both in the tutorials section.

Hint: AMFPHP will be faster.

boyzdynasty
04-17-2003, 11:43 PM
now i'm all confuse...then can you tell me why this works

the file is attach.

....dam...the file is too big.... can you PM me your e-mail?
I just want to show I didn't have to do AMFPHP stuff....
Maybe you can explain to me why what I have works.

freddycodes
04-18-2003, 01:33 AM
All you did was pass back a couple of variables in a url encoded string in the sample you sent me. Arrays are complex data structures, especially multi-dimensional arrays like you have in your post above. You would be best off using PHP to create XML to old the records. Or check out AMFPHP, which I use and it makes my life so much easier.

boyzdynasty
04-18-2003, 01:47 AM
ok. I'll check out the tute.

boyzdynasty
04-18-2003, 02:00 AM
i think there is a problem....
The Flash Remoting Components extend the Macromedia Flash MX authoring environment

The FLASH REMOTING COMPONENTS is only use for test out the codes on the local machine, right?

but when I upload the final code and the necessary amfphp files to the linux machine that I am using will there be any complications?

What I am trying to say...is...do I need to configure the web-server or....it should just work.

I'm asking b/c I don't want to spend a lot of time understanding something when in the end I can't use it. :rolleyes:

freddycodes
04-18-2003, 02:41 AM
That is incorrect, you will not have to do much on your server, provided you can read the install instructions for AMFPHP ;)

boyzdynasty
04-18-2003, 04:12 PM
if I read it correctly.... it seems all I have to do is make sure those PHP files are save in the root-web directory!!!

I hope that is correct. It doesn't seem so bad.