Forum Moderators: open
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
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.