AS3 rollover or mouseover use instructions _flash AS3

Source: Internet
Author: User
Tags garbage collection
So when you listen to the Mouseevent.roll_over event, the mouse moves to a few of the panel's buttons, the program still thinks the mouse hovers over the panel. Suppose we monitor mouseevent.mouse_over, as the mouse moves to the Panel button, the program immediately judge the mouse left the panel, has been to the top of the button-this result is not what we need, at this time should go to click the button, the result of the program to judge the mouse left the panel, will be directly removechild or visible=false.

About bubbling, it is necessary to mention the flow of AS3, simply a catch-target-bubbling process: After the event occurs, first from the display layer of the root container down the level of the hierarchy to capture until the target object to distribute the event to return to bubble up, The target attribute in this event always points to the most internal distribution event target, and Currenttarget points to the object currently in the event stream.
After an event occurs, from the root node to the parent node of the target node, all nodes have two chances to respond to the event, respectively, in the capture and bubbling stages. Registering a listener on any node that the event flows through will trigger. Of course, the premise is to turn on the capture and bubbling feature.

By default, the Capture function is turned off because, in actual development, the listening target is clear and does not need to be captured.
The event bubbles only if the Bubbles property is true, and the default bubbling event includes: Change,click,doubleclick,keydown,keyup,mousedown,mouseup. Once the capture is turned on, the default bubbling will be canceled.
Therefore, in the same listener can not be opened at the same time capture and bubbling, can only register two listening to one open capture one open bubble.
Only visual objects (containers, controls) have a capture and bubbling phase, while non-visual objects such as Xml,webservice have only the target phase.

The registered listener method is:
AddEventListener (type:string, Listener:function, Usecapture:boolean=false, priority:int=0, useWeakReference: Boolean=false)
Usecapture is the ability to turn on capture,
Priority for priority setting, when there are more than one listener, the larger the priority, the higher the priority is called first, if the same level is registered in the order of the call. Note here that even precedence has no guarantee that the previous listening function has finished executing when the last listening call executes.
Useweakreference is a weak reference switch, which is recommended to be true to facilitate automatic garbage collection. But the most normative or direct removeeventlistener. Note When the registration listener opens the capture, the usecapture of RemoveEventListener (type:string, listener:function, Usecapture:boolean=false) must be set to true. otherwise invalid

The event object is constructed in the following ways:
Event (type:string, Bubbles:boolean=false, Cancelable:boolean=false)
Whether the bubbles is bubbling
When cancelable is true, you can call the Preventdefault method to stop the system default behavior. such as input text, the default behavior is immediately displayed in the text area, and when Cancelable is true, call the Preventdefault method so that the characters do not appear.
In addition, there are two ways to stop the continuation of the flow of events, Stoppropagation and stopimmediatepropagation, except that the former does not stop the object being processed. The latter also stops other listeners on the same object.

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.