I l @ ve RuBoard |

Comparing two things in ActionScript is simple. You use standard mathematical symbols, such as ## Are the Values the Same? You have already seen how the So, if you want to see whether variable a is the number 7, use var a = 7; trace(a == 7); This code assigns the value 7 to the variable When you test this code, the Output window will show "true." If you set
You can also use the var myString = "Hello World."; trace(myString == "Hello World."); trace(myString == "hello world."); When you run this program, you get both a "true" and a "false." This is because the first comparison matches the variable to exactly the same string, whereas the second comparison demonstrates that comparisons of strings take case into account. Suppose that you want to test to see whether two values are not equal to each other. In this case, you use the special operator var a = 7; trace(a != 9); trace(a != 7); The first ## Less Than or Greater Than You can also compare two things to see whether they are less than or greater than each other. To do this, use the standard mathematical symbols var a = 7; trace(a < 8); trace(a > 6); trace(a < 1); You should get a "true," "true," and "false" from this program. The variable You can also use the var a = 7; trace(a <= 9); trace(a >= 5); trace(a >= 7); All three of the preceding statements are "true." ## Operators You can also modify the values of variables with operations. They are also standard mathematical symbols such as For instance, to add 4 to a variable that contains the number 7, we just use a second assignment statement that sets the value of the variable to its current value, plus 4: var a = 7; a = a + 4; trace(a); The result is 11, of course. ActionScript actually has some shorthand for performing the same addition. The var a = 7; a += 4; trace(a); There is another piece of shorthand that you should be familiar with. The var a = 7; a++; trace(a); The result is 8. Now try this: var a = 7; trace(a++); trace(a); The result is first a 7 and then an 8. What happened here? Well, the first Now try this: var a = 7; trace(++a); trace(a); You will get two 8s this time. This is because when you place the You can use |

I l @ ve RuBoard |

Sams Teach Yourself Flash MX ActionScript in 24 Hours

ISBN: 0672323850

EAN: 2147483647

EAN: 2147483647

Year: 2002

Pages: 272

Pages: 272

Authors: Gary Rosenzweig

flylib.com © 2008-2017.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net