PDA

View Full Version : Cheap way to use PHP cookies in flash:)


TrustyProphet
01-18-2005, 08:37 PM
First, I'd like to thank Laguana for helping me a lot...so...thanks!!! :)

Now onto something that I tried for the past week and a half to figure out.

This is a VERY cheap method to get this to work, but it works, and the only way to even tell the variables are there, is to look at the source.

I looked everywhere for a method of opening cookies to send the variables to flash, and it seems that either you have to have the variables already in flash, or have some text displayed that you don't want. So, after having flash redirect to a different page this whole time, I decided to use DHTML layers :)

First, in your flash file, you'll need to call the variables from the PHP page...theres a bunch of things on how to do this, so just look inside another post ;)

Second, in your php file (or whichever contains the flash movie), open the cookie like usual, and echo the variables like so:

echo "&variable1=" . $variable1 . "&variable2=" . $variable2 . "&";

I put the "&" on the end to stop it from reading anything past that as a variable. So now flash can read it, but you have some unwanted text showing on your page...how to get rid of this? Simple! Stick the text behind the flash file :p

echo "<div style='z-index: 1; position: absolute; top: ??; left: ??'>&variable1=" . $variable1 . "&variable2=" . $variable2 . "&</div>";

Wrap the flash code in div tags too, and set the z-index to 2 so that it's above the text. :rolleyes:

Now I know this is probably the most obvious thing to do, and not the most proper, but it works, and I checked around my whole flash file to see if I could somehow highlight the variable text that was echoed and I can't.

If this helps at least one person on here then I'll be happy! Take care and thanks again Laguana for the help in the previous topic!

Matt C.

Leebzie
03-11-2005, 09:08 AM
I havent investigated this yet but I was thinking of simply declaring it invisible with CSS ?

EDIT : ok tried it, seems to work good - Ill be tackling the same sort of problem exactly (flash cookies) so Ill see how this solution works.


<style>
h1.variables
{
visibility:hidden;
position:absolute;
left: 0px;
top: 0px;
z-index:-10
}
</style>
<body>
<h1 class="variables"> <?php echo "&variable1=" . $variable1 . "&variable2=" . $variable2 . "&";?> </h1>
</body>


Any advice for how to approach using cookies ? Ive never done it before - what I want to do is have a flash movie dump some variables into a cookie when its closed (it goes off to another address) and when it reopens it checks if the variables are there and reloads them. The AS side I should be fine with, its just the PHP.

Its a shopping cart BTW. Have been reading about mysharedobject, would I be better off going with that ?