FORUMS: list search recent posts

AS 2.0 Passing variables from Flash to PHP

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
John Cruz
AS 2.0 Passing variables from Flash to PHP
on Jul 28, 2008 at 6:12:12 pm

Hi, I'm pretty new to actionscript and I am trying to re-create an html based login thru a flash front end. The html login passes along 2 variables from a form to the PHP script, how do I do this with Flash? I'm pretty sure I have the input boxes setup properly in Flash but I am having trouble with the actionscript code to pass along the variables. I've been trying to do this with a combination of the LoadVars command and getURL, but I'm pulling my hair out. Any help would be greatly appreciated. Thanks all!

Return to posts index

Pieter Helsen
Re: AS 2.0 Passing variables from Flash to PHP
on Jul 28, 2008 at 11:49:23 pm

No need for the getURL, you were on the right track with the LoadVars :)

// Create a loadVars object to store the results from the PHP File.
var result_lv:LoadVars = new LoadVars();
// Do something once the results from PHP have loaded into Flash.
result_lv.onLoad = function(success:Boolean) {
// If the PHP returned a value
if (success) {
//Output that value
result_ta.text = result_lv.myVariable;
} else {
// Else, return an error.
result_ta.text = "Error connecting to server.";
// Create another loadVars object to store the variables that you
// will be sending to PHP.
var send_lv:LoadVars = new LoadVars();
// Store the values from the textfields in here.
send_lv.username = username_txt.text;
send_lv.password = password_txt.text;
// Send the variables to your php script using the POST method and
// store the results in the result_lv loadVars object.
send_lv.sendAndLoad("", result_lv, "POST");

In your php file use $_POST['username'] and $_POST['password'] to get to the username and password values.

When login is successful echo something like this:
echo "&myVariable=loggedin&";
if unsuccessful:
echo "&myVariable=failed&";
(don't forget the ampersants. This is to seperate variables.
This is interpreted by Flash and stored in the result_lv object as result_lv.myVariable.

Hope that helps.

Kind regards,

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.

Return to posts index

John Cruz
Re: AS 2.0 Passing variables from Flash to PHP
on Jul 29, 2008 at 5:20:40 am

Hi Pieter,

Thanks for the response, you definitely have me heading in the right direction, but I'm still having some trouble. I don't need anything sent back to Flash, just the variables passed to the PHP script, from there the PHP script should take over. Below is the ActionScript code I have on the button:

on (release) {
var sendVar:LoadVars = new LoadVars();
sendVar.username = username_txt.text;
sendVar.password = password_txt.text;

It opens a new browser, but does not pass along the variables. Below is my PHP script:

$username = $_POST['username'];
$password = $_POST['password'];

Again any help would be much appreciated. Thanks!

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved