Difference between revisions of "Actionscript"
From Wikicliki
(→Operators) |
(→Operators) |
||
Line 25: | Line 25: | ||
this._rotation += 5; // makes mc rotate by 5 degrees clockwise for each tick of frame rate | this._rotation += 5; // makes mc rotate by 5 degrees clockwise for each tick of frame rate | ||
};</pre> | };</pre> | ||
+ | |||
+ | === Checking/Comparing Values === | ||
+ | |||
+ | * == checks for logical equality | ||
+ | * != checks for logical inequality | ||
+ | * === checks for logical | ||
+ | |||
+ | <pre>trace(5 == 6); // displays: false | ||
+ | trace(5 == 6); // displays: false | ||
=== Conditionals === | === Conditionals === |
Revision as of 17:00, 22 September 2008
Contents
Basics
Operators
- + for addition
- - for subtraction
- asterisk for multiply
- / for divide
these two are the same:
myNum = myNum + 6; myNum += 6;
- ++ add one
- -- decrease by one
those can be postfix or prefix operators but remember that only prefix affects it immediately.
myNum = 5; trace(myNum++); // displays 5 (adds one to next trace) trace(myNum); // displays 6 (has added one from the postfix) trace(++myNum); // displays 7 (adds one as its a prefix)
use this incremental thing to modify property over time:
my_mc.onEnterFrame = function () { this._rotation += 5; // makes mc rotate by 5 degrees clockwise for each tick of frame rate };
Checking/Comparing Values
- == checks for logical equality
- != checks for logical inequality
- === checks for logical
trace(5 == 6); // displays: false trace(5 == 6); // displays: false === Conditionals === <pre>var message = "yellow"; // the equal sign assigns values to variables trace ("big " + message + " truck"); // prints "big yellow truck" if (message == "yellow") { // the double equal sign checks to see if variables are equal trace ("yes, i did say big yellow truck."); // prints "yes, i did say big yellow truck" trace (typeof message); // prints "string" var x = a; // prints "number" trace (typeof a) }
var x = 1; while (x <= 5) { // as long as x is less than 5... trace (x); // return 1 in output x = x + 1; // return 2 3 4 5 in output }
Reusable functions
Runtime Environment
Include external actionscript file
#include "filename.as" // includes the .as file at runtime (must be in same folder as .fla)
Detecting player/OS
Setting movie dimensions
Color
Setting RGB
Setting Transparency
Transform and restore RGB
Controlling RGB with sliders
Drawing
Numbers
Rounding Numbers
Text Field
Arrays
Oh no.