views:

31

answers:

2

Hi guys, how can I pass a string from PHP to Flash?

I need to pass this to flash,

$var = 'uid_'.$uid.'_'.'likes_'.$likes;

Any ideas on how I can accomplish this?

Thanx in advance!

+1  A: 

The simplest way to achieve is to use the well-named flashvars to pass it. Adobe as a KB about flash HTML parameters http://kb2.adobe.com/cps/127/tn_12701.html

Javascript based flash integration libraries (like swfObject) allow to pass any of these parameters as well.

Benoit
I need to pass the string on demand, so passing it via the flashvars wont work too well, unless I am misunderstanding it?Thanx for the reply!
Sorry for misunderstanding your question, you can then use Myk solutions, I would recommend URLLoader + XML data for simple transfer. Go into AMF and other remoting solutions only if really needed.
Benoit
+1  A: 

So, your best bet in this case is going to be one of two things:

1) If this is a simple easy solution with a little bit of data that isn't going to see a whole ton of traffic, just have your PHP output an XML file and use Flash's URLLoader() to load in that .xml data - then parse it.

Alternately,

2) If this is going to see some heavy traffic, or if you want to do it the "right" way, look into either ZendAMF or AMFPHP. Lee Brimelow has tutorials for working with this stuff at gotoandlearn.com - basically, you can remote into a PHP Web Service which will return data (not just strings - you can even do typed objects!) as binary data directly into your Flash file.

Either way you're not going to have too much trouble with it - it's a pretty straightforward operation. Let me know if you have any questions.

Myk