C Style:
/* This is a
multiline comment. */
Datatype | Examples |
---|---|
Boolean | true or false |
Number | 3542.433, 0, -143.54, 0xFFFF00 |
String | "hello", 'abc', " " (space), "" (empty string) |
\n New Line \r Carriage Return \t Horizontal Tab \\ Backslash \' Single Quote \" Double Quote
var b:Boolean = true;
var s:String = "cat";
var b:Boolean = new Boolean(true);
var s:String = new String("cat");
= =+ =- =* =/ =%
++ --
< <= > >= == !=
=== !==
&& || !
? :
instanceof typeof
Datatype | Return String |
---|---|
Boolean | "boolean" |
Number | "number" |
String | "string" |
MovieClip | "movie clip" |
All other types | "object" |
// Create array with three elements.
var a:Array = new Array(3);
// Create array by initialization.
var a:Array = ["dog", "cat", "mouse"];
// Modify an array element.
a[3] = "horse";
// Obtain a value from an array.
x = a[3];
// Prepending to the beginning of an array.
a.unshift("Gerbil", "Ferret");
// Inserting into an array.
// 2 is the starting index.
// 0 is the number of elements to delete.
a.splice(2, 0, "Gerbil", "Ferret");
// Splitting a string into an array.
a = s.split(",");
// Extract a subset of an array.
b = a.slice(2, 5);
b = a.slice(2);
b = a.slice(2, -3);
b = a.slice(-3);
// Get the length of a string.
len = s.length;
// Extracting a substring with substr.
// 3 is the starting index.
// 6 is the length of the extracted string.
u = s.substr(3, 6);
u = s.substr(-4, 6);
// Extracting a substring with slice.
// 3 is the starting index.
// 9 is the ending index.
u = s.slice(3, 9);
u = s.slice(3);
u = s.slice(-4, 9);
u = s.slice(-9);
// Change the case of a string.
u = s.toLowerCase( );
u = s.toUpperCase( );
// Casting from a number to a string.
s = n.toString(s);
// Casting from a boolean to a number.
n = b ? 1 : 0;
// Casting from a boolean to a string.
s = b ? "true" : "false";
// Casting from a number to a boolean.
b = n != 0;
// Casting from a string to a boolean.
b = s == "true";