PDA

View Full Version : PHP/mysql to Flash to PHP/mysql...Help with user database


TrustyProphet
01-15-2005, 12:57 AM
I spent the past 3 days and finally got variables loaded from a php file into flash, but those are predefined variables. What I'm trying to do but can't seem to figure out how, is to have somebody click on a link to goto a flash game, then the flash file calls a php file which reads the users cookie (for their username and score), passes it into flash where the user can play the game, then whenever their score changes, it's sent back to php to be put back into the database...

My problem is the php file that flash is calling won't read the users cookie. I'm guessing it's because the user isn't really at that page...so is there any other way to do this? I really don't want to have a bunch of &username=username&score=score stuff within the players sight, so naturally it's on another page. I'll worry about going from flash back to php later on, unless somebody wishes to explain that too ;)

Not too sure if this would be more appropriate for a PHP forum...but I'm guessing this would be solved using some sorta actionscript...I know it has to be possible...

Thanks in advance everybody!!

Matt C.

Laguana
01-15-2005, 03:53 AM
Do you mean cookie as in javascript cookie style thing? If the only purpose of that cookie is flash stuff, you could look into using shared objects instead. Or if you mean information from the database about their previous game, then you'd want to look into using sendAndLoad.

TrustyProphet
01-15-2005, 10:06 PM
Thanks for the response!

Sorry about putting this in the wrong forum before, I didn't even notice this one:(

I can take information from the database and put it into Flash no problem, but what is giving me a problem is the fact that it has to pull information out dependant upon the user. The cookie will be used for other things, like html blogs, editting, and a few other things, but since it contains their username, I figured I could use it. If I put the information on the same php page where the flash file is, it would work, because the cookie would open and display the user, and flash could take it from there, but it would display a nasty bit of text on the page...not a good idea.

Heres my structure...

I have playgames.php, which includes the flash file. The actionscript in the flash file uses loadVariablesNum to take variables from playgamesa.php, which of course is a completely seperate page. The current user on that page cannot be read, because that file isn't accessed by the user, it's accessed by flash...but that's what I need to figure out a way to do. I'm so close to feeling like quitting trying this, but it's something I'm not only curious to figure out how to do, I need to find out how... Any solutions are very very helpful!:) Thanks!!

Laguana
01-16-2005, 01:49 AM
I'd use sendAndLoad.

Basically, you work out all the variables you want the php to get from the user. In flash, you take those variables, and put them onto a loadVars object. then you have something like this:

varsToSend = new LoadVars()
varsToSend.username = 'user'
varsToLoad = new LoadVars()
varsToSend.sendAndLoad('url', varsToLoad)

That will then send the variables from varsToSend to the url with a post method (you can use get too if you want) and take the response in the varsToLoad loadVars object. In the php you'd then take the varables from teh $_POST['id'] array, in this case user would be $_POST['username'] as that's the variable it was stored in on the flash side of things. Then you'd do the sql query with php, and echo the results back as &variablename=variabledata& etc, and the varsToLoad will then have those variables.

Hope it helps :)

TrustyProphet
01-16-2005, 03:28 AM
Just reading all that makes my head feel like it's going to explode, but will try for at least 6 hours and then get back to you with results:) Thanks so much for the help, I appreciate it a ton!!

TrustyProphet
01-16-2005, 11:45 PM
Still having the same problem :( The code you gave me was easier to understand though :). I know what's wrong, but it seems like with flash, theres no way to fix it...

Flash has nothing to send, because the username is stored in a php cookie (this is used by other php stuff). If I input it into flash on the page that flash loads on, I'd have a nasty "&username=$username" showing, so I'm directing it (flash...using sendAndLoad) to another page like I should...But since the variables I need are in the cookie, flash alone can't access them, and directing the user to that page would show them only the "&username=$username." I really hope that what I'm trying to do isn't right under my nose and I'm just off by one ore two lines, because I'll feel bad having wasted everybodies time:( Once I DO get this up, I'll see if I can write a tutorial or something and post it up on here about it so nobody else has the same prob. Thanks again!!