Actionscript evaluation issue

  • deafdigit
  • Newbie
  • Newbie
  • deafdigit
  • Posts: 7

Post 3+ Months Ago

Code: [ Select ]
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;
    }

    }
}
  1. on (release)
  2. {
  3.     err_msg.text=''
  4.     if(userName.length > 0 && userPassword.length > 0)
  5.     {
  6.         var loginVars = new LoadVars();
  7.         loginVars.action = 'login';
  8.         loginVars.username = userName.text;
  9.         loginVars.pass = userPassword.text;
  10.         loginVars.sendAndLoad(php_file, loginVars, 'POST');
  11.         loginButton.enabled = false;
  12.         loginVars.onLoad = function() {
  13.       if (!this.error) {
  14.                 if (this.user > 0) {
  15.                     err_msg.text='It works. User greater than 0 ' + this.user;
  16.                 } else if (this.user == 0) {
  17.                     err_msg.text='User = 0 ' + this.user;
  18.                 } else {
  19.                     err_msg.text='Somethings rotten ' + this.user;
  20.                 }
  21.             }
  22.             else {
  23.                 if(this.error != undefined) {
  24.                     err_msg.text='error, but not undefined';
  25.                 } else {
  26.                     err_msg.text='error is undefined';
  27.                     }
  28.             }
  29.             userName.selectable = true;
  30.       userPassword.selectable = true;
  31.       loginButton.enabled = true;
  32.     }
  33.     }
  34. }


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
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

what i'm thinking is that the variables which you receive in the loginVars are treated like strings.
Therefor try to transform them into int, so use this:
Code: [ Select ]
var intUser:Number = parseInt(this.user);
if (intUser > 0) { .... }
else if (intUser == 0) {....}
else {... }
  1. var intUser:Number = parseInt(this.user);
  2. if (intUser > 0) { .... }
  3. else if (intUser == 0) {....}
  4. else {... }
  • deafdigit
  • Newbie
  • Newbie
  • deafdigit
  • Posts: 7

Post 3+ Months Ago

*sigh* I really thought my coding skills were beyong data type mismatch ****-ups.

IceCold, you are indeed a guru - thank you so much! This was very, very helpful.


[Problem solved]

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 5 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.