RSS link icon

Flash actionscript else if tutorial 

 

This flash tutorial is about if statements, one of the most used things in OOP (object oriented programming) languages like actionscripting. Once you learn and understand it you will be able to do a lot with programming.

 

flash tutorial if statement

 

If conditions are build up of different things but its the same for almost every programming language, so if you learn it once, you will now it if you have to learn another language later on.

Here is how a simple if condition will look like in flash actionscript.

if (condition) { trace("hello world") } 

This will output hello world if the condition is true. Here is a real life example.

var i = 1
if (i < 10) {
	trace(i);
}

First we set a variable to be equal to 1, just so we have something to check for, then in the if statement, we check if our variable is less than 10, then it should output the number i, if not, then nothing will happen.

Now we can advance our if statement, so that if the condition did not come out true, we have something else done.

if (condition) {
	trace("hello Bob")
} else {
	trace("hello David")
}

This is pretty simple if you understand our first example. Now we have an output saying hello Bob if the condition came out true, but if not, whatever else then it will say hello David.

 

The final thing we need, is to set up multiply conditions in the same if statement, it will look like this.

if (condition) {
	trace("hello Bob")
} else if (condition) {
	trace("hello David")
} else {
	trace("goodbye")
}

Now this is the more advanced if structure, but when you learn it, it will become your life long friend. First we have the condition as in the other examples, if it comes out true we have hello Bob, then the new part is we have put up another condition with the else if, and if that comes out true we have hello David. Finally if none of the above conations are true, we have an output saying goodbye instead.


Random Guy says: Monday, January 07, 2008

it is much better and easier to use the switch statment for the longer Chr(34)if elseChr(34).


Arne says: Sunday, December 30, 2007

ow btw its ball.x in AS3 now, just to prevent confusion ;)


mar4o says: Saturday, December 29, 2007

good tut!:)

bruce, you can apply this to many things, for example:

if (ball._x == 100){
trace ("You have won!");
}else{
trace ("Game Over!");
}


Admin Bob says: Saturday, December 15, 2007

Hi bruce, well, how you apply this is quite easy, depends what you try to achive. here is an example where I used a lot of ifChr(34)s for a small game.

http://www.blog.0tutor.com/post.aspxid=48&titel=Roll-the-dice-Flash-game-tutorial


bruce says: Wednesday, December 12, 2007

i understand the tutorial, but how do aply that to something

   


 

 

 

 4

 
 
   Web Premium
 
 

All rights reserved, Copyright 2008. Contact