...

View Full Version : Actionscript evaluation issue



deafdigit
10-06-2009, 12:56 PM
Hi guys,


I'll make it short:

I'm writing a login-system for my website. It checks for the appropriate username and password in my database via a php-script and returns "user=" and a value. The value it returns IS the rigth one - I just can't get flash to evaluate it. What I want is:

if this.user is 0 then deny access (with a gotoAndStop(frame)) and if this.user > 0 then grant access.

What's wrong with this validation?


on (release)
{
err_msg.text=''
if(userName.length > 0 && userPassword.length > 0)
{
var loginVars = new LoadVars();
loginVars.action = 'login';
loginVars.username = userName.text;
loginVars.pass = userPassword.text;
loginVars.sendAndLoad(php_file, loginVars, 'POST');
loginButton.enabled = false;
loginVars.onLoad = function() {
if (!this.error) {
if (this.user > 0) {
err_msg.text='It works. User greater than 0 ' + this.user;
} else if (this.user == 0) {
err_msg.text='User = 0 ' + this.user;
} else {
err_msg.text='Somethings rotten ' + this.user;
}
}
else {
if(this.error != undefined) {
err_msg.text='error, but not undefined';
} else {
err_msg.text='error is undefined';
}
}
userName.selectable = true;
userPassword.selectable = true;
loginButton.enabled = true;
}

}
}

No matter the value of this.user, the err_msg always writes "It works. User greater than 0" and then the value of this.user.
As you can see, after each evaluation attempt I print the value of this.user. If I've inputted a wrong set of username and password, then this results in:
"It works. User is greater than 0 0" (The zero being the value of this.user).
Am I using the operators in the wrong way?


Thanks in advance,
deaf_digit

[Paul Ferrie ]
11-19-2009, 10:47 AM
php will return a string even though it's a number.
check for a string instead of a number and you should be sorted.


if (this.user != "0") {
err_msg.text='It works. User greater than 0 ' + this.user;
} else if (this.user == "0") {
err_msg.text='User = 0 ' + this.user;
} else {
err_msg.text='Somethings rotten ' + this.user;
}



hope it helps



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum