7 Replies Latest reply on Nov 27, 2009 8:12 AM by pauland

    Creating an If Statement in Flex That Produces Multiple Results

    jimmyoneshot Level 1

      I have created a small login window for my flex app and once the user enter's an appropriate username and password I want the username to be displayed at the top but I also want a new window to appear. To do this I require an if statement to be activated nce the user clicks on a sign in button which will either produce the text "Invalid username or password" or log the user in and do a couple of things. It is the doing a couple of things part that I'm struggling with. Here is my if statement so far that activates when the sign in button is clicked:-

      if (usernameEntry.text=='usernametest' || passwordEntry.text=='passwordtest') loginNotificationLabel.text='You Are Logged In' || accountLinks.visible=true else loginNotificationLabel.text='Invalid Username or Password'

       

       

      It is the || accountLinks.visible=true part that is giving me errors. Basically if the username and password are correct I want a new window I've created 'accountLinks' to become visible as well as the 'loginNotificationLabel' text to display the message "You Are Logged In" but I can't figure out how to get that particular statement to work.

        • 1. Re: Creating an If Statement in Flex That Produces Multiple Results
          pauland Level 4

          if (usernameEntry.text=='usernametest' || passwordEntry.text=='passwordtest')

          {

               loginNotificationLabel.text='You Are Logged In';

               accountLinks.visible=true;

          } else{

               loginNotificationLabel.text='Invalid Username or Password';

          }

           

          You're mixing up conditional statements and forgetting statement blocks.

           

          You might like to look into states, too.

           

          Paul

          1 person found this helpful
          • 2. Re: Creating an If Statement in Flex That Produces Multiple Results
            JAcques TRIPOZ Level 1

            if (usernameEntry.text=='usernametest' ||

            passwordEntry.text=='passwordtest')

            {

            loginNotificationLabel.text='You Are Logged In';

            accountLinks.visible=true;

            }

            else

            {

            loginNotificationLabel.text='Invalid Username or Password' ;

            }

            jimmyoneshot a écrit :

            I have created a small login window for my flex app and once the user enter's an appropriate username and password I want the username to be displayed at the top but I also want a new window to appear. To do this I require an if statement to be activated nce the user clicks on a sign in button which will either produce the text "Invalid username or password" or log the user in and do a couple of things. It is the doing a couple of things part that I'm struggling with. Here is my if statement so far that activates when the sign in button is clicked:-

            if (usernameEntry.text=='usernametest' || passwordEntry.text=='passwordtest') loginNotificationLabel.text='You Are Logged In' || accountLinks.visible=true else loginNotificationLabel.text='Invalid Username or Password'

             

            >

             

            It is the || accountLinks.visible=true part that is giving me errors. Basically if the username and password are correct I want a new window I've created 'accountLinks' to become visible as well as the 'loginNotificationLabel' text to display the message "You Are Logged In" but I can't figure out how to get that particular statement to work.

            >

            1 person found this helpful
            • 3. Re: Creating an If Statement in Flex That Produces Multiple Results
              jimmyoneshot Level 1

              Thanks a lot to you both. The strange thing is it seems if the user only matches one of those conditions they still get the results i.e. logged in message and acoount links window appearing whereas they should need to get both the username and the password correct to be logged in. It even works if they leave the username blank and enter just the password correctly and vice versa. How can I fix that statement so that user's need to get both correct before being logged in?

              • 4. Re: Creating an If Statement in Flex That Produces Multiple Results
                pauland Level 4

                if ((usernameEntry.text=='usernametest' )&&( passwordEntry.text=='passwordtest'))

                 

                It's always good to be explicit with brackets.

                 

                &&  "AND"

                ||     "OR"

                 

                Paul

                • 5. Re: Creating an If Statement in Flex That Produces Multiple Results
                  jimmyoneshot Level 1

                  Ok I've now changed it to this however compiling it produces the error "The entity name must immediately follow the '&' in the entity reference". It was this error that made me use the || in the first place as I thought it was an alternative to && that may not produce the error:-

                   

                  if ((usernameEntry.text=='usernametest') && (passwordEntry.text=='passwordtest')) {loginNotificationLabel.text='You Are Logged In'; accountLinks.visible=true;} else{loginNotificationLabel.text='Invalid Username or Password';}

                   

                   

                  • 6. Re: Creating an If Statement in Flex That Produces Multiple Results
                    pauland Level 4

                    For actionscript, the statement is fine. I suspect that you may have another problem - have you properly wrapped this code in a script tag?

                     

                    The kind of error that you are seeing is related to bad parsing of XML/MXML.

                     

                    || is NOT an alternative to &&  !

                     

                    Paul

                    • 7. Re: Creating an If Statement in Flex That Produces Multiple Results
                      jimmyoneshot Level 1

                      Nope but you may be right there. I was just putting it straight into the click function itself as I didn't think it'd matter. I'll try putting it in a script now instead. I guess someone else informed me wrong about the || but now I know better.

                       

                      Cheers mate. All the best.