0

I tried searching over so many threads, my problem still can not be resolved after 8 hours of trying. I created a login/register for AS3 through php/MySQLi. I am trying to return a few variables from php to "account page" which after successful login, AS3 will automatically jump to account page, and display "username" and "other variables", at the moment i am just trying to use "password" to test it out. I can successfully, display the username. But when i try to load more than 1 variables, problem start to occur. I can use event.target.data and echo that. That works but when i try to trace event.target.data.username, it stops working, when there is something attached after data.

Below are my codes. AS3

var Bend:URLRequest = new URLRequest("http://localhost/dummy.php");
Bend.method = URLRequestMethod.POST;



var variabless:URLVariables = new URLVariables();
variabless.username = Nam.text;
Bend.data = variabless;


var nLoader:URLLoader = new URLLoader();
nLoader.dataFormat = URLLoaderDataFormat.TEXT;
nLoader.addEventListener(Event.COMPLETE,Jandler);
nLoader.load(Bend);


// handler for the PHP script completion and return of status
 function Jandler(event:Event):void{



       Nam.text=event.target.data.$name;
       Nam2.text=event.target.data.$password;

}

I have no idea what the php should be, but i started the sesssion from login.

session_start();

echo $_SESSION['username']=$name;
echo $_SESSION['password']=$password;

Thanks for your time, and help.

New AS3

function Jandler(event:Event):void{

     var responseVariables:URLVariables = new URLVariables(event.target.data);

     trace(responseVariables.names);
       trace(responseVariables.password);

New php

session_start();
$_SESSION['username']=$names;
$_SESSION['password']=$password;

echo "names=$names&password=$password";

1 Answer 1

1

On the AS3 side, it's best to convert the data to a URLVariables object like this :

var responseVariables:URLVariables = new URLVariables(e.target.data);

Now you can work with the data a bit easier, for example :

trace (responseVariables.name)

If you don't do this, it's basically just a big long string containing your parameter string.

On the php side, you need to be creating a parameter string that is a combination of parameters names and values, delimited by a & like this :

echo "name=Clark&password=light";

If it's not delimited by the &, it's going to seen on the as3 side as one parameter.

Sign up to request clarification or add additional context in comments.

5 Comments

I attached the updated AS3 and Php above, but i have undefined for the result. Any idea?
Based on your PHP, it should be undefined. I don't see where you assign a value to $name or $password.
I'd check that the php file returns what you expect if you check it in your web browser. Get in a habit of checking that you are dealing with good data. It's not good practice to worry about the AS3 side of things until your PHP script is returning what you 'expect' it to be returning.
Ah ok thanks, i am very new to AS3 and php, so i am not very sure how to test out the codes, i am testing it out through Flash pro on test mode everytime.
Right, but first you need verify that the PHP script is returning the parameter string you expect. That's what I'd do first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.