So when the mouse moves to several buttons of the panel after listening to the MouseEvent.ROLL_OVER event, the program still thinks the mouse is hovering above the panel. Suppose we listen to MouseEvent.MOUSE_OVER, as the mouse moves to the panel button, the program immediately determines that the mouse has left the panel and has reached the top of the button - this result is not what we need. At this time, we should have clicked the button, but the program determines that the mouse leaves the panel, and will directly removeChild or visible=false.
Regarding bubbles, we have to mention the event stream of AS3. Simply put, it is a loop process of catching - target - bubbles: after an event occurs, it starts from the root container in the display layer to capture one by one at the bottom level until it reaches the target object of the dispatch event and then returns to bubble upwards. The target attribute in this event always points to the innermost dispatch event target, and the currentTarget points to the current object in the event stream as the name implies.
After the event occurs, from the root node to the target node's parent node, all nodes have two chances to respond to the event, respectively in the capture and bubble stages. Registering a listener on any node through which the event stream passes will trigger. Of course, the premise is that the capture and bubbling functions are turned on.
By default, the capture function is turned off because in actual development, the listening target is clear and there is no need to capture it.
Events will only bubble when the bubbles attribute is true. The default bubble events include: change, click, doubleClick, keyDown, keyUp, mouseDown, mouseUp. Once the capture is turned on, the default bubbling will be cancelled.
Therefore, it cannot be opened to capture and bubble at the same time in the same listener. You can only register two listeners, one to capture and the other to bubble.
Only visual objects (containers, controls) have capture and bubble stages, while non-visual objects such as XML and WebService have only target stages.
The method of registering a listener is:
addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false)
useCapture means whether to turn on the capture function.
priority is a priority setting. When there are multiple listeners, the larger the priority, the higher the priority, the more it is called first. If it is the same level, it will be called in the order of registration. Note here that even if there is priority, it is impossible to ensure that the previous listening function has been executed when the next listening call is executed.
useWeakReference is a weak reference switch, recommended to set to true, for automatic garbage recycling. But the most standard thing is to directly removeEventListener. Note that when the registration listener has enabled capture, the useCapture of removeEventListener(type:String, listener:Function, useCapture:Boolean=false) must be set to true, otherwise it will be invalid.
The construction method of event objects is:
Event(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
Bubbles means whether bubbles are bubbling
When cancelable is true, the PreventDefault method can be called to stop the system's default behavior. For example, when entering text, the default behavior will be displayed in the text area immediately. When cancelable is true, the PreventDefault method is called so that the characters do not appear.
In addition, Event has two methods to stop the event stream from continuing propagation, stopPropagation and stopImmediatePropagation. The difference is that the former will not stop the object being processed. The latter will also stop other listeners on the same object.
Regarding bubbles, we have to mention the event stream of AS3. Simply put, it is a loop process of catching - target - bubbles: after an event occurs, it starts from the root container in the display layer to capture one by one at the bottom level until it reaches the target object of the dispatch event and then returns to bubble upwards. The target attribute in this event always points to the innermost dispatch event target, and the currentTarget points to the current object in the event stream as the name implies.
After the event occurs, from the root node to the target node's parent node, all nodes have two chances to respond to the event, respectively in the capture and bubble stages. Registering a listener on any node through which the event stream passes will trigger. Of course, the premise is that the capture and bubbling functions are turned on.
By default, the capture function is turned off because in actual development, the listening target is clear and there is no need to capture it.
Events will only bubble when the bubbles attribute is true. The default bubble events include: change, click, doubleClick, keyDown, keyUp, mouseDown, mouseUp. Once the capture is turned on, the default bubbling will be cancelled.
Therefore, it cannot be opened to capture and bubble at the same time in the same listener. You can only register two listeners, one to capture and the other to bubble.
Only visual objects (containers, controls) have capture and bubble stages, while non-visual objects such as XML and WebService have only target stages.
The method of registering a listener is:
addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false)
useCapture means whether to turn on the capture function.
priority is a priority setting. When there are multiple listeners, the larger the priority, the higher the priority, the more it is called first. If it is the same level, it will be called in the order of registration. Note here that even if there is priority, it is impossible to ensure that the previous listening function has been executed when the next listening call is executed.
useWeakReference is a weak reference switch, recommended to set to true, for automatic garbage recycling. But the most standard thing is to directly removeEventListener. Note that when the registration listener has enabled capture, the useCapture of removeEventListener(type:String, listener:Function, useCapture:Boolean=false) must be set to true, otherwise it will be invalid.
The construction method of event objects is:
Event(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
Bubbles means whether bubbles are bubbling
When cancelable is true, the PreventDefault method can be called to stop the system's default behavior. For example, when entering text, the default behavior will be displayed in the text area immediately. When cancelable is true, the PreventDefault method is called so that the characters do not appear.
In addition, Event has two methods to stop the event stream from continuing propagation, stopPropagation and stopImmediatePropagation. The difference is that the former will not stop the object being processed. The latter will also stop other listeners on the same object.