Welcome to WebmasterWorld Guest from 54.221.73.104

Forum Moderators: open

Message Too Old, No Replies

Sending/Receiving Variables between Flash/PHP

     

PartisanEntity

3:40 pm on Jan 9, 2010 (gmt 0)

5+ Year Member



Hi all,

I am quite a newbie at ActionScript and for a class project I am trying to develop a car configurator, this flash app is supposed to be embeded into a web CMS that I have developed in PHP.

But before I even start that, I am trying to understand how Flash can send and receive data to/from php.

My issue is this: the user logs in through my php pages and a number of session variables are set, these contain things such as the username of the user, email, etc...

Now I would like to pass these session variables to Flash.

As far as I understood it, this is how I have to proceed:

1. Use FlashVars to pass the session id of the user during loading of the flash movie/app.

2. The flash movie/app then sends the sessionid to a php script which outputs all session variables of that sessionid.

3. Now the flash movie/app has access to all the session variables.

My problem is that since I am new at ActionScript I am not so familiar with the syntax.

Here is what I have, if someone can point me in the right direction I would really appreciate it:

My embed script which passes the sessiond id as a FlashVars:

<object classid="clsid:(blah)" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="800" height="800" id="ZoomifyHotspotViewer">
<param name="flashvars" value="phpsessionid=<? print session_id(); ?>">
<param name="src" value="test.swf">
<embed flashvars="phpsessionid=<? print session_id(); ?>" src="test.swf" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="800" name="YourSWF"></embed>
</object>

My actionscript which attempts to send the session id to the php (it's not working, I am not sure why):

//send the sessionid to the flash page
send("http://www.example.com/flash.php?sid=" + phpsessionid, "", "POST");

myData = new LoadVars();

myData.onLoad = function(){
placeTheDataIntoTheRightPlace();//call the function that handles the data.
};

myData.load("http://www.example.com/flash.php");

placeTheDataIntoTheRightPlace = function(){

t_username.text = myData.username;

};

Finally, my flash.php script:

<?php
//info for flash

//start the session using the session id passed by the flash movie
session_id($_POST['sid']);
session_start();

//the username
echo '&username='.$_SESSION['username'];
echo '&loggedin='.$_SESSION['logged_in'];

?>

If someone could tell me what I have done wrong I would really appreciate it.

Thanks

rocknbil

12:26 am on Jan 11, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I don't use FlashVars, I use other methods, but here's a couple things I spot right off that may help.

What you are doing here,

<param name="flashvars" value="phpsessionid=<? print session_id(); ?>">

and here, for Moz browsers,

<embed flashvars="phpsessionid=<? print session_id(); ?>"

is passing only the variable "phpsessionid" to your program. So as an experiment, try doing this in your A.S.:

t_username.text = phpsessionid;

and the text field should display the value of phpsessionid.

Without digging through the docs on LoadVars(), I can't tell if your method in flash.php will work or not.

PartisanEntity

7:27 pm on Jan 11, 2010 (gmt 0)

5+ Year Member



Hi, thanks for your feedback, the problem was that my send() and load() calls were being given seperate session id's by the server. Combining them worked.