View Full Version : passing arrays back to flash

05-26-2003, 03:13 PM
i am currently sending a string back to flash and parsing out the data in it using actionscript. Is there any way to pass the array back and obtaining an array variable in flash?
currently this is what im doing

echo "&returnvars=";
for($i = 0; $i < $length; $i++)
echo $returnvars[$i];
echo " ";
i want to just be able to return $returnvars and have flash use the array. cause the way im doing it now, flash has to a lot of extra work just to reformat the values and it seems like its kinda stupid doing it like this......

05-26-2003, 05:47 PM
Not natively, since data types are different in flash than they are in PHP. But using something like amfphp, its very easy.


You can use other things like WDDX, but there is overhead involved with all of them.

05-26-2003, 06:18 PM
great stuff, thanx

05-27-2003, 12:06 PM
downloaded the docs for afmphp. It says that i need flash remoting packages installed, but this costs 1k :( so i assume that downloading the components will do the trick?
the amfphp docs also state that they arent sure if afmphp is legal:eek: any toughts on that anyone?

05-27-2003, 12:18 PM
I think you need this one...


05-27-2003, 04:06 PM
Yep like CyanBlue said, those components are a free download. As far as the legality issues go, I had the same concern, however Macromedia has yet to comment on the legal issues of this product. If you are concerned you could try PHPObject, there is a tutorial o nthat one in the tutorials section of this site. I myself and not too worried since its been out for some time now and MM has not said they have a problem with it. They claim that amfphp does a fraction of what the 1K version they have does, which is probably true, if you care about ColdFusion and .NET interaction. But for just getting data in and out of flash it does the trick.

05-27-2003, 10:27 PM
probably, but it seems to me that loadvars could become legacy pretty quickly (unless used for tiny transfers....)
although i think i will try and solve the problem with both versions - my actionscript could use the practice

05-27-2003, 10:29 PM
Yes LoadVars can be used for quite a bit including loading in recordsets, its just a whole lot easier to hook existing PHP classes up to flash with remoting.

05-29-2003, 09:16 PM
Hey, i was finally able to upload arrays without anything extra!!

status = "Logging in" ;
forum = function(id, name) {
this.id = id ;
this.name = name ;
forums = new Array() ;
f_php = new LoadVars() ;
f_php.load("http://localhost/board/viewboard.php?username=Clinton&password=*****") ;
f_php.onLoad = function(success)
if( success )
i=0 ;
offset = 0 ;
for( var temp in f_php )
switch( offset )
case 0 :
tmp_name = f_php[temp] ;
offset ++ ;
break ;

case 1 :
forums[i] = new forum( f_php[temp], tmp_name ) ;
offset = 0 ;
i++ ;

else {
status="NOOOOO!!!" ;

It uses the for...in loop, and while it returns it somewhat backwards, i easily worked around it. What do you guys think?
It works perfectly, and i can upload any amount or complexity of data i want! :D

05-29-2003, 09:23 PM
That is just one of many many ways to upload complex data types from PHP to Flash. Again, whatever works for you is fine, whether it be LoadVars(), XML, AMF. Whatever suits your fancy.

The advantage to remoting is the automatic conversion of native data types form one platform to another.

05-29-2003, 10:47 PM
i had mine working, just seemed like i was doing it the hard way and there should have been an easier way to do it.....
amf will do for my when its time to pass complex arrays back and forth.....
then again, im new to actionscript and am making mistakes........

04-19-2004, 03:13 PM
Hey all,

I'm looking to pass an array to flash from asp. The following method isn't workign for me:

contents of foo.asp

response.write "a=[1,2,3]"

where I use
loadVariablesNum("foo.asp", 0, "GET");

and some dynamic text boxes to see if I got the data correctly. Any advice?

04-19-2004, 03:44 PM
Howdy and Welcome... :)

You cannot send the array like that... Flash understand that as a whole string, so it is not working that way... You need to make the output to be something like 'a=1|2|3' and use split() function within the Flash to parse it back to an array...