Skip to main content
Known Participant
August 16, 2014
Answered

Sending variables from flash AS2 to php mySQL

  • August 16, 2014
  • 3 replies
  • 2885 views

Hi adobe I have a question. So I have finally created a login/register system with php and mysql and flash as2. That works and here is the link:lumosityentertainment.hostei.com/PhPLoginSystem.swf

But I have a question. How do I send variables from flash as2 to my mySQL database? And then how do I load them up from mysql to flash as2? Also when the variables get edited or changed like if I had 6 gold and then now I have 7 gold how do I make flash send that updated data to my database? I know you use php and stuff but can I have examples of easy php and as2 codes? I'm a beginner in php but I know a decent amount of AS2. I've been searching all around google and adobe forums for the answer but none of them really helped. I'm currently working on a flash game on my website and I'm trying to make it so players can save like their gold,armor,weapons etc. and then load them when logging into their accounts.  Here is my game I currently use cookies to save data:

lumosityentertainment.enjin.com/playfantasydreams

This topic has been closed for replies.
Correct answer kglad

var sendLV:LoadVars=new LoadVars();

var receiveLV:LoadVars=new LoadVars();

receiveLV.onData=function(src:String){

trace(src);  // or whatever for debugging

}

sendLV.somedata=somedata;

sendLV.someotherdata=someotherdata;

sendLV.sendAndLoad("yourphp.php",receiveLV,"POST");

/////////////////////////////////

////

//php

.

.

$somedata=$_POST['somedata'];

$someotherdata=$_POST['someotherdata'];

//write to your sql

if(whatever){

echo 'success';

} else {

echo 'failure';

}

/////////////////////////////////

p.s when using the adobe forums, please mark helpful/correct responses, if there are any.

3 replies

Known Participant
August 18, 2014

For the php code do I need to add <?php

//all the codes

<?

Like do I need to add the <?php thingy? Becuase you didnt add it in your example. Also whats the difference between GET and POST? And which should I use?

kglad
Community Expert
Community Expert
August 18, 2014

yes, you need to use a valid php file.

use POST. it uses an associative array and get appends the variable/values to the url.

Known Participant
August 18, 2014

What is the src in your AS2 code? That's really confusing me. Like in trace(src); what's supposed to be the src inside the parenthesis? Is it just some string? Sorry I don't really create that many functions when coding in AS2.

Known Participant
August 17, 2014

Like what are the codes I know that you need to do the loadvars and sendAndLoad etc.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 17, 2014

var sendLV:LoadVars=new LoadVars();

var receiveLV:LoadVars=new LoadVars();

receiveLV.onData=function(src:String){

trace(src);  // or whatever for debugging

}

sendLV.somedata=somedata;

sendLV.someotherdata=someotherdata;

sendLV.sendAndLoad("yourphp.php",receiveLV,"POST");

/////////////////////////////////

////

//php

.

.

$somedata=$_POST['somedata'];

$someotherdata=$_POST['someotherdata'];

//write to your sql

if(whatever){

echo 'success';

} else {

echo 'failure';

}

/////////////////////////////////

p.s when using the adobe forums, please mark helpful/correct responses, if there are any.

kglad
Community Expert
Community Expert
August 16, 2014

use the loadvars sendAndLoad method.