Http://www.flexs.cn/post/flex_as3_08221.html
[Try, catch, finally]
Private function tryerror (): void {
Try {
Trace ("Test start-Try ");
Throwerror ();
} Catch (errobject: Error ){
Trace ("error message:" + errobject. Message );
Trace ("test end-catch ");
Return;
} Finally {
Trace ("Although the return method already exists in catch,CodeWill still be executed. In fact, no matter whether the return method is in try or catch, the code in finally will always be executed ");
}
Trace ("there is already a return, and this will not be executed again. Unless no error is thrown, so that the code in the catch is not executed ");
}
Private function throwerror (): void {
Throw new error ("Throw error ");
}
[Screen Resolution Detection]
Flash. system. capabilities. screenresolutionx
Flash. system. capabilities. screenresolutiony
[Center the pop-up windowAlgorithm]
X = (stage width/2)-(window width/2)
Y = (stage height/2)-(window height/2)
Conversion between numbers in different hexadecimal formats]
Parseint (STR: String, Radix: uint = 0): Number returns the decimal number. The radix parameter indicates the base number of The number to be analyzed. if radix is omitted, the default value is 10, unless the string starts with "0x", "0x" or "0 ":
Trace (parseint ("0x12"); // set Radix to 16 and output to 18.
Trace (parseint ("017"); // set Radix to 8, output: 15
Or use the tostring (Radix) method of the number, uint, and INT objects.
[Use math. Round () to round a number]
Math. Round ()
Trace (math. Round (204.499); // output: 204
Trace (math. Round (401.5); // output: 402
[Use math. Floor () to round down a number, that is, as long as the integer part does not care about the decimal part]
Trace (math. Floor (204.99); // output: 204
[Use math. Ceil () to round up a number. If the fractional part is not zero, add 1 to the integer part]
Trace (math. Ceil (401.01); // output: 402
[Generate a random number]
Use math. Random () to generate a pseudo-random number n, where 0 <= n <1
[obtain a random number within the specified value range]
// optional range: [min, Max]
private function randrange (Min: Number, Max: Number): Number {
var randomnum: Number = math. floor (math. random () * (max-min + 1) + min;
return randomnum;
}