Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author: Nick Kouvaris
»  Title: Znax
»  Description: Znax is a board game. Click 4 tiles of the same color and form squares as big as you can. You will erase all the tiles inside the square and collect points. Get maximum score if you make a square with game edges.
»  More by: Nick Kouvaris


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4941 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  Author Agence WOP Digital Agency
»  Title: Electricdrum
»  Description: French WOP Agency, 3D websites, Flash (Papervision, Away 3D), event or institutional projects. The agency operates on all digital projects: consulting, design, graphic design, development, online communication. The WOP agency follows you on the implementation of original, creative and optimized digital projects.


Random Links | Add your own Flash Related Links
Flash Tutorials 1481 Tutorials 7 New Tutorials Added!
What's New | Top100

» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» How To Make A Fathers Day Slideshow
» How To Make A Transparent Background of Your Flash File
» Create Flash Banner With Text Disco Light Effect Today we will introduce you a Text Disco Light eff
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting/Basic

Categories Flash Actionscript Programming Basics
Author: Steve Happ | Website: http://www.video-animation.com |

 
Page 3
«prev 1 2 3 4 5 next»

Arithmetic "IF" operator

The syntactic form is:
Expression1 ? expr2 : expr3 ;
If expression1 evaluates to a true condition, then expression2 is evaluated, otherwise expression3 is evaluated. E.g.

x = 2;
y = 5;
max = x

Bitwise Operators

Bitwise operators operate on the value to base 2 (binary). Operands must be integers.
Left Shift ("<<") - shifts the bits of the left operand some number of positions to the left. e.g.

someNum = 1;
0 0	0 0	0 0 0 1
SomeNum = someNum<<1;
0 0 0 0 0 0 1 0
SomeNum = someNum<<2;
0 0 0 0 1 0 0 0
Right Shift (">>")
SomeNum = someNum>>3;
0 0 0 0 0 0 0 1
The leftShift operator inserts "0" from the right.
The Right Shift operator inserts "0" from the left.

Variables (AS 2.0)

A variable is identified by a user-supplied name. Each variable is of a particular data type. E.g.

Var num:Number;
"Number" is a type specifier. A declaration can follow the template:
var variableName:DataType;
  • The use of the ":Datatype" is not strictly enforced in AS2 but I strongly recommend it.
  • A variable can be composed of letters, numbers and underscore. Upper and lower case letters are different.
  • Variables need to be initialised. I.e. given an initial value.
    var myNum:Number;	//Declaration
    myNum = 0;		//Initialisation
    
  • In AS 1.0, variables are not strictly typed and can change types.

DataTypes (AS 2.0 only)

Variables in AS 2.0 can be given strict datatypes such as a Number or a String or a Boolean. e.g.

var myNum:Number;
var myString:String;
var isTested:Boolean;
In AS 1.0 there is no strict datatyping. A number can become a String and vice versa. e.g.
num = 10;
num = "Test";
Strict datatyping can capture errors.

Compiler Errrors

  1. Syntax errors - e.g. var numberOne:
  2. Spelling Mistakes - var mc:MoveiClip;
  3. DataType Errors - (AS 2.0)

var num1:Number;
var str1:String;
num1 = "Steve";
str1 = 27;

Flow control

IF

An if statement tests a condition. If it is true, then a set of actions is executed. Otherwise, the set is ignored or bypassed. Here is a template :

 If(expression){
 Statement1;
 }
Here is an example :
 var x = 23;
 if(x>3){
 trace("x is greater than 3");
 }

IF .. ELSE

If .. else allows for a kind of either .. or condition.
Template:

If(expression){
 Statement1;
 }else{
 statement2;
 }
If expression is true then statement1 is executed.
If expression is false then statement2 is executed.
e.g.
var x = 2;
if(x> 3){
trace("condition is true");
}else{
trace("condition is false");
}

Switch (AS 2.0 only)

A switch statement is an alternative to complex nested if .. else statements

switch(variable){
 case 1:
 //Statement1;
 break;
 case 2:
 //Statement2
 break;
 default:
 //statement3;
 break;
 }
The variable to be evaluated is inserted into the switch argument. If the first variable's value is 1 then statement1 is evaluated. A break statement is inserted after it so that the switch statement is terminated. The default label is the condition for "everything else".
var tester:Number;
tester = random(3);
switch (tester) {
case 1 :
 trace("tester = 1");
 break;
case 2 :
 trace("tester = 2");
 break;
case 3 :
 trace("tester = 3");
 break;
default :
 trace("Out of range");
 break;
}

«prev 1 2 3 4 5 next»

» Level Basic

Added: : 2005-08-10
Rating: 8.17 Votes: 12
Hits: 674
» Author
Steve Happ is the founder of Steve's Tutes and has been going hard at it developing Flash for Web and CD-rom.
» Download
Download the files used in this tutorial.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments