Summary of use tips for as in flash

Source: Internet
Author: User

Core tip:Flash experience Summary of as use.

are summarized in the project, after the practice, under the Flex2 AS3 use.

As Tune JS

Externalinterface.call ("JS function name", parameter: array); (can receive return value)

JS Tune as

As:ExternalInterface.addCallback ("function name (string)" used in JS, functions in AS (function type));

Function name (parameter) used in js:swf name. js;

Object cleanup:

As in if an object is not used and no object references it, the object is reclaimed by the collector (not necessarily when), so the object used must be processed (such as the addition of listening to delete, etc.), otherwise the President occupies the memory.

Redraw:

Flash in the blocked objects will also be redrawn, such as in a position non-stop drawing circle, painting to hundreds of or thousands of layers, when the mouse through this block will feel the slow speed, look at the CPU state will see the CPU is full, but does not occupy memory.

To determine the object type:

If (A is type) {}

Get Object type:

Trace (typeof object) Output Object type

Type conversion:

var A: type = B as type;

Strong turn:

var A: type = type (b);

Judge the number:

isNaN (expression), note return False when number

Timer

Do not think timer can be extremely accurate; Use timer interval not less than 10 milliseconds.

Private,protected,internal,public access Rights

Private: can only be accessed within the class itself

Protected: Can be accessed by the class itself or by any child class.

Internal: Can be accessed by the class itself or by any class within the same package;

Public: can be accessed within a class or by a class instance

The difference between for...in and for each...in

Unlike the for...in loop, the iteration variable in the for Each...in loop contains the value saved by the property, not the name (or primary key, index) of the property.

For example: Var obj:object={name1:value1,name2:value2};

For...in took out the name,for each...in removed the value.

Object:

All objects in as can be converted by default, and an array can be used as a map.

However, when used as an array, there is no guarantee of order.

Like what:

var array:array = new Array ();

Array["a"] = new Object ();

ToolTip

If the tooltip display is prohibited,

1.this.truncatetofit = false; (does not appear ...)

2. Rewrite updatedisplaylist, and finally super.tooltip = null;

Reflection:

ClassType = Flash.utils.getDefinitionByName (className) as Class;

New ClassType ();

An error occurred while GMT was formatted. (such as China time zone, 1970/01/01 08:00 error, has been confirmed to be a flex bug)

Replace All

There is no replaceall function in as, to implement this function you can use regular expressions

For example: Replace the ': ' in 00:00:00 ' with ' to ' be implemented as follows

var teststr:string = "00:00:00";

var repedstr:string = Teststr.replace (/:/g, "");

/:/g G is not less, G represents global

As Object Deep Clone method:

Private Function Clone (_source:object):* {

var copier:bytearray = new ByteArray ();

Copier.writeobject (_source);

copier.position = 0;

Return (Copier.readobject ());

}

Methods of mx_internal types can also be overloaded: (not recommended)

The following declaration needs to be made at the bottom of the import-

Use namespace Mx_internal







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.