This tutorial is for actionscript 2.0

commands/statements to be covered:

[ccN_actionscript]stop();[/ccN_actionscript]
[ccN_actionscript]gotoAndPlay();[/ccN_actionscript]
[ccN_actionscript]_parent.[/ccN_actionscript]
[ccN_actionscript]gotoAndStop();[/ccN_actionscript]
[ccN_actionscript]if { }[/ccN_actionscript]
[ccN_actionscript]else if { }[/ccN_actionscript]
[ccN_actionscript]else { }[/ccN_actionscript]

Definitions:

The [ccNi_actionscript] stop(); [/ccNi_actionscript] command:
The stop command is used to stop your flash file from moving further in its time-line.

The [ccNi_actionscript]gotoAndPlay();[/ccNi_actionscript] command:
The gotoAndPlay command does exactly what it sounds like, it goes to a frame in the time-line, and has the time-line continue playing from there.

The [ccNi_actionscript]gotoAndStop();[/ccNi_actionscript] command:
The gotoAndStop command is just like the gotoAndPlay command except once it goes to the designated frame, it stops progressing further in the time-line.

The [ccNi_actionscript]if(){ }[/ccNi_actionscript] statement:
The if statement is used to restrict a script action from occurring unless a certain requirement or condition is met.

The [ccNi_actionscript]else if() { }[/ccNi_actionscript] statement:
The else if statement is used after the if statement when the if statements requirement is not met and the programmer wants to check for a different requirement and designate a different response to be taken if the new requirement is met.

The [ccNi_actionscript]else() { }[/ccNi_actionscript] statement:
The else statement is used after the if statement or else if statement if the programmer wants an action to be executed on the event that none of the requirements listed in the if/else if statement(s) are met.

Usage:

[ccN_actionscript]Stop();[/ccN_actionscript]
The stop command can only be placed as action-script in a frame. Just write "Stop();" anywhere in the action-script of a frame, and the time-line will stop progressing at that frame.

[ccN_actionscript]gotoAndPlay();[/ccN_actionscript]
The gotoAndPlay command can only be placed as action-script in frames or movie-clips. in a frame, all you need to do is place the command in the frame you want to skip from and place the frame number you want to skip to inside the (). for Example: [ccNi_actionscript]gotoAndPlay(5);[/ccNi_actionscript] placed in a frame will cause the time-line to skip from the frame where the command is written to frame 5 and have the time-line continue to play from there.
If you write this command as action-script in a movie-clip placed in your main time-line, your movie-clip will [ccNi_actionscript]gotoAndStop(5);[/ccNi_actionscript] instead of your main time-line because movie-clips have time-lines of their own, and the time-line it is placed on is it's "parent". to control the main time-line (in this case the movie-clip's parent) you must access. You can access the parent of a movie-clip simply by typing _parent. before the command. So to control the main time-line from this movie-clip, you can type [ccNi_actionscript]_parent.gotoAndStop(5);[/ccNi_actionscript] furthermore, if you place yet another movie-clip inside this movie clip, the main time-line becomes the new movie-clip's parent's parent. So, to access the main time-line from this movie-clip inside the original movie-clip, just type [ccNi_actionscript]_parent._parent.gotoAndStop(5);[/ccNi_actionscript] It's that simple.

[ccN_actionscript]if(){ }[/ccN_actionscript]
To use the if statement, you must first know what requirement or condition you are looking to see is met. You must then know what you want to happen if that condition is met. For example, ill use this script: (to be placed in a frame)
Code:

var Toms_color = "green";
var Arias_color = "blue";
var Jacksons_color = "red";
var Brians_color = "blue";
var Nicks_color = "red";

if(Toms_color == "red"){
trace("Toms color is red");
}
if(Toms_color == "blue"){
trace("Toms color is blue");
}
if(Toms_color == "green"){
trace("Toms color is green");
}

As you can see, you type:

if(*condition*){
*action if condition is met*
}

I used == instead of = because == is used if you want to compare two variables for equivalence. = is used if you want to make a variable equivalent to a different variable.

you can even make if statements like:
Code:

if(1 + 1 + 1 == 3){
trace("I can do math!");
}

[ccN_actionscript]else if(){ }[/ccN_actionscript]
The else if statement is written just like the if statement. The difference is that there MUST be an if statement or another else if statement before it, and its condition can only be met if none of the conditions before it are met. For example:

Code:

var Toms_color = "green";
var Arias_color = "blue";
var Jacksons_color = "red";
var Brians_color = "blue";
var Nicks_color = "red";

if(Toms_color == "red"){
trace("Toms color is red");
} else if(Toms_color == "blue"){
trace("Toms color is blue");
} else if(Toms_color == "green"){
trace("Toms color is green");
} else if(1 + 1 == 2){
trace("this condition will not be met");
}

because the condition [ccNi_actionscript]if(Toms_color == "green")[/ccNi_actionscript] is met, the else if statement [ccNi_actionscript]if(1 + 1 == 2)[/ccNi_actionscript] will not be checked.
If however you change Toms_color to "purple", the condition [ccNi_actionscript]if(Toms_color == "green")[/ccNi_actionscript] will not be met, and [ccNi_actionscript]if(1 + 1 == 2){[/ccNi_actionscript] will be met.

[ccN_actionscript]else{}[/ccN_actionscript]
The else statement MUST be used after an if statement or an else if statement. The else statement will only execute if none of the statements before it are met. For example:

Code:

var Toms_color = "Purple";
var Arias_color = "blue";
var Jacksons_color = "red";
var Brians_color = "blue";
var Nicks_color = "red";

if(Toms_color == "red"){
trace("Toms color is red");
} else if(Toms_color == "blue"){
trace("Toms color is blue");
} else if(Toms_color == "green"){
trace("Toms color is green");
} else {
trace("Toms color is not red, green, or blue, it is "+Toms_color);
}

Because Toms_color does not equal red,blue, or green, the else statement is triggered, and the trace command is output.

functions that can be used in these statements:

[ccNi_actionscript]==[/ccNi_actionscript] (is equivalent to)
[ccNi_actionscript]!=[/ccNi_actionscript] (is not equivalent to)
[ccNi_actionscript]>[/ccNi_actionscript] (is greater than)
[ccNi_actionscript]<[/ccNi_actionscript] (is less than) [ccNi_actionscript]>=[/ccNi_actionscript] (is greater than or equal to)
[ccNi_actionscript]<=[/ccNi_actionscript] (is less than or equal to) you can also shorten your script by placing multiple conditions in one if/else if statement by using [ccNi_actionscript]&&[/ccNi_actionscript] or [ccNi_actionscript]||[/ccNi_actionscript]. using [ccNi_actionscript]&&[/ccNi_actionscript] is almost like saying "and". using [ccNi_actionscript]||[/ccNi_actionscript] is almost like saying "or". in [ccNi_actionscript]&&[/ccNi_actionscript], all of the conditions must be met. in [ccNi_actionscript]||[/ccNi_actionscript], only one of the conditions must be met. For example: Code:
if(1+1==2 && 1+2==3 && 1+3==4){
trace("this will be displayed because all of the statements are true.");
}

if(1+1==2 && 1+4==3 && 1+3==4){
trace("this will not be displayed because 1 + 4 != 3.");
}

if(1+1==2 || 1+4==3 || 1+4==4){
trace("this will be displayed because at least one of the statements is true, 1 + 1 = 2");
}

Be Sociable, Share!