Learning AS3: The only class variable

Source: Internet
Author: User
Tags arrays event listener variables
Variable (this article is not direct translation, the original text is as follows:)
In ActionScript 2, variables defined within a class ' s body were defined in the class ' s prototype object. This is a efficient means to handle variable definitions but it also meant that complex data types (such as Arrays) had A tendency to is "shared" among instances if not explicitly defined for instances the class within. This are no longer a problem with ActionScript 3. class variables defined in the class are now unique to each class instance so this problem no longer occurs.

In AS2, complex data types (such as arrays), if initialized directly outside of a method in the class body and not initialized in the constructor, are understood as "shared" data and are shared by all instances (similar to static effects). But this problem does not exist in the AS3. A class variable is unique to each instance and is unique to a variable. As follows:

Class myclass{

private var List:array = [1,2,3]; There will be some problems in AS2, AS3 is very good

Public Function MyClass () {
In AS2, you should initialize the list here
}
}* the new MouseMove behavior


MouseMove behavior has changed in AS3. Previously, the MouseMove action was a global concept, which meant that no matter where the mouse was in Flashmovie, as long as it moved, it would trigger any movieclip mousemove behavior.

In AS3, the mouse object is no longer used to assign (Dispath) mouse behavior. For MouseMove behavior, you should listen for a interactiveobject instance, such as Sprites,movieclip and stage. Therefore, you may need to use interactiveobject instead of mouse to receive listening. For each Interactiveobject instance, the MouseMove behavior is performed only within the scope of the object. If you want to use the global mouse event listener, you need to add a listener to the stage.

Therefore, when you use MouseMove to drag an object, when your mouse leaves the detached object, the object of the MouseMove event will be invalidated, the drag effect is also effective. At this point, you may need to add a move behavior to the stage to listen:

Stage.addeventlistener (Mouseevent.mouse_move, dragmyobject);

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.