| Getting Started - Conditions and MovieClip Movement |
|
|
|
| Written by Smash |
| Thursday, 23 July 2009 03:17 |
What are Conditions and how do I use them?It is suggested that you first view the tutorial video at the bottom of this article for a better understanding of the text. A condition is a way to run code only when something (something being the condition) is true, if it is true then a section of code is run, if it is false the code is not run. A condition is created like this
Here we check to see if the variable x is greater than y, and if that is true, we run the code. we have other conditional operators to use such as
we can also string 2 conditions together like this Here we use the && symbol or and. Basically we are saying, if x is greater than y AND y is less than z then run the code. We can also use || or the OR symbol This code is basically saying, if x is greater than y OR y is less than z then run the code With this you can start programming some serious stuff, with our current knowledge lets try making our circle go back and forth. In this code we create a variable to see which direction the movieclip should be moving, if it reaches the very right goRight become false, when it reaches the very left goRight becomes true, and the movement is handled by the other 2 conditional statements. The best way to learn is to play around as much as you can, see what other things you can make! |



