Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the stages of the Flex event mechanism

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what are the stages of the Flex event mechanism". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "what are the stages of the Flex event mechanism?"

Basic Concepts in Flex event Mechanism

Event objects (event object): all event objects are flash.events.Event or their subclasses. For example, mouse event MouseEvent, timer event TimerEvent. Each event object includes an event type (type) and an event source (target) so that event listener knows the type of event and who throws such an event. To put it simply, event objects are objects of various event types in ActionScript.

Event dispatchers (event source): is the subject of the event initiation. All dispatcher are EventDispatcher or its subclasses. The event trigger source must provide an API for listener to register the event (register). To put it simply, the event source is a control.

Event listeners (event listener): it is often represented as a function in AS 3.0. We must register a listener for each particular event and event source, and when an event occurs, the event source (dispatcher) notifies the listener to handle the established event. Simply understood, a listener is a function.

Register listener

You can register in AS 3.0 through the following syntax format.

Dispatcher.addEventListener (eventName, listener)

Of course, there is another format in Flex, which directly defines a handler for the events of a control in the mxml file, such as

Event phase in Flex event mechanism

We divide event triggers into two categories: events thrown by elements displayed in the interface and events thrown by elements that are not displayed in the interface. Very simple, for example: a * * class, such as the complete event thrown by a URLLoader object to load images or other resources, belongs to the * * class. The click event thrown by a button on the interface is the second type, which triggers an event flow and triggers a series of events, which is divided into three phases: capture, target, and bubble.

Capture phase (capture)

At this stage, Flash Player will look for the trigger source of the event, which is traced down layer by layer through the root display element (root display object) until it finds the source of the event, such as the button object found by Flash Player after you click on button. By default, the monitor (listener) will not receive any messages at this stage (by default, messages will only be received in the target and bubble phases).

If you want listener to receive the message and take action during the capture phase, you can change the third parameter to true when registering, as shown in the following method: object.addEventListener (MouseEvent.CLICK, onClick, true)

This stage sounds strange, but in fact it is rarely used. But it plays an important role in the flow of events. It can be captured by application before the event reaches the child element (child elements), which, of course, prevents the event from reaching the child element.

Target execution phase (target)

At this stage is the execution phase of the event, which is the code that we usually use to handle the event flow.

Bubbling stage (bubble)

This stage of * is actually the reverse process of * stages. It emits the event to the parent element step by step through the child element after the event code has been executed, all the way to the root element. You don't need to specify anything specifically for the listener at this stage, you just need to register the event normally. The listener is notified at this stage. But only if the event can be bubble.

Garbage collection

Flash Player implements garbage collection by referencing counters (reference counting) and marking and clearing (mark and sweep).

The reference counter is simply the technology assigned to each object. Once the counter of the object is 0, it means that the object may no longer be used and can be safely cleared. Its disadvantage is that it can not solve the problem of circular reference, once there is a circular reference, it can not be garbage collected through this method.

Marking and purging (mark and sweep) is to solve the problem of circular reference. It traverses each active and reachable node in the program, and once it is found that some nodes are outside the active node, it is considered to be no longer useful and can be recycled.

These two mechanisms are jointly run in the garbage collection process to ensure the correct recovery of resources. But they can't recycle the garbage caused by program errors. The registration of listeners is the most likely to cause this problem.

These are all the contents of the article "what are the stages of the Flex event mechanism?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report