Setting a cookie with Flash
Most web programmers know the value of using a cookie to store data between a users visits. Cookies keep passwords, shopping carts contents and preferences of many kinds stored on the user's computer until they need it. Flash provides us with the shared object that can either be set to be accessed only by the file that made it, or for any other swf file. For Example:
//make shared object and read values
var so:SharedObject = SharedObject.getLocal("foo", "/");
uname = so.data.email2;
pass2 = so.data.pass2;
email = so.data.email;
//write to sharedObject
This works great if you want flash to read the variables later, but what if you need to access information in php but that has been written by flash? Or if you need to read in flash a cookie set by php?
Flash contains a command called loadVars() which as one may guess was made for loading a variable into flash. However when flash tries to load a variable from a php page all the script on that page is executed, thus giving all the power of PHP to Flash.
So to set a cookie from flash or to execute any php script from flash we only need one line of action script.
The code for the setCookie PHP is as follows
setcookie($mycookie,$myvalue,time() + 31536000);
to read the cookie in Flash or PHP later use this script:
//write out for flash
you can call this or any other php script by using the loadVariables method above. This will allow you to hook flash to Databases, Rss and many other web services
|» Level Intermediate|
Rating: 6 Votes: 5
|William Clarkson is a flash programer who has worked throughout the US and Asia. He now runs several websites and a consuliting company in Wisconsin|
|Download the files used in this tutorial.|
|Download (0 kb)|
|More help? Search our boards for quick answers!|