Flex and as3 tips

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.