Conditionals are what make programming smart. Conditionals ask questions, and based on the answer, they either do or do not execute code associated with them. The type of question they ask is a simple yes or no, or rather a true or false question such as whether one number is greater than another.

When building a conditional, such as the if statement, you put a condition within parenthesis that the conditional looks at. If the condition is met, in other words, if it is true, then the code associated with the if statement is run. If it is not met, or is false, the entire code within is skipped over.

Programmers use conditionals to set boundaries, verify information, and make logical decisions. For instance, if we had a simple login for a page, we would want to verify if the user's name and password were correct. The code for that might look something like this:

 if(userName == correctUserName){      if(userPass == password){           trace("welcome");      }else{           trace("password incorrect");      } }else{      trace("no user found"); ) 

The preceding code checks to see if the userName given is the correct user. If so, it then checks to see if the password is correct as well. If both are correct, a welcome message is sent to the Output panel. If the userName is correct, but the password is not, another message is sent to the Output panel. And if the user has not entered the correct user name, a different message is sent to the Output panel for that as well.

You can see how conditionals follow a path of logic and can be used in many circumstances, as you will see as you work through the other chapters.

You can find more information on conditionals in Chapter 11, "Statements and Expressions."

Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319 © 2008-2017.
If you may any questions please contact us: