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;
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
- Syntax errors - e.g. var numberOne:
- Spelling Mistakes - var mc:MoveiClip;
- 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;
}
| » Level Basic |
|
|
Added: : 2005-08-10
Rating: 8.17 Votes: 12
Hits: 670
|
| » 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.
|
|
|