📜  Flex-事件处理

📅  最后修改于: 2020-10-25 02:26:06             🧑  作者: Mango


Flex使用事件的概念根据应用程序中的状态或用户交互将数据从一个对象传递到另一个对象。

ActionScript具有通用的Event类,该类定义了处理事件所需的许多功能。每次在Flex应用程序中发生事件时,都会从Event类层次结构中创建三种类型的对象。

事件具有以下三个关键属性

Sr.No Property & Description
1

Type

The type states about what kind of event just happened. This may be click, initialize, mouseover, change, etc. The actual values will be represented by constants like MouseEvent.CLICK.

2

Target

The target property of Event is an object reference to the component that generated the event.If you click a Button with an id of clickMeButton, the target of that click event will be clickMeButton

3

CurrentTarget

The currentTarget property varies container hierarchy. It mainly deals with flow of events.

事件流程阶段

事件经过三个阶段来寻找事件处理程序。

Sr.No Phase & Description
1

Capture

In the capture phase, the program will start looking for event handlers from the outside (or top) parent to the innermost one. The capture phase stops at the parent of the object that triggered the event.

2

Target

In the target phase, the component that triggered the event, is checked for an event handler.

3

Bubble

The Bubble phase is reverse of capture phase, working back through the structure, from the target component’s parent on up.

考虑以下应用程序代码-



   
   
      
      

当用户单击按钮时,他或她还单击了面板和应用程序。

该事件经历三个阶段,以寻找事件处理程序分配。

弹性活动阶段

让我们按照以下步骤测试Flex应用程序中的事件处理:

Step Description
1 Create a project with a name HelloWorld under a package com.tutorialspoint.client as explained in the Flex – Create Application chapter.
2 Modify HelloWorld.mxml as explained below. Keep rest of the files unchanged.
3 Compile and run the application to make sure business logic is working as per the requirements.

以下是修改后的mxml文件src / com.tutorialspoint / HelloWorld.mxml的内容



   
   
   
   
   
      
         

         
            
               
            
            
            

准备好所有更改后,让我们像在“ Flex-创建应用程序”一章中一样,以正常模式编译和运行应用程序。如果您的应用程序一切正常,它将产生以下结果:[在线尝试]

弹性事件处理