Reputation: 449
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";
Upvotes: 0
Views: 255
Reputation: 6751
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.
Upvotes: 1