在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Flex使用事件概念将数据从一个对象传递到另一个对象,这取决于应用程序中的状态或用户交互。 ActionScript有一个通用的 Event 类,它定义了处理事件所需的大部分功能。 每次在Flex应用程序中发生事件时,都会创建来自Event类层次结构的三种类型的对象。 事件具有以下三个关键属性
事件流阶段事件经过三个阶段寻找事件处理程序。
考虑以下应用程序代码 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" minWidth="500" minHeight="500" > <s:Panel> <s:Button id="clickMeButton" label="Click Me!" click="doAction( );"/> </s:Panel> </s:Application> 当用户单击按钮时,他或她也单击了面板和应用程序。事件通过三个阶段寻找事件处理程序分配。 让我们按照以下步骤在Flex应用程序中测试事件处理:
以下是修改后的mxml文件 src / com.tutorialspoint / HelloWorld.mxml 的内容。 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" minWidth="500" minHeight="500" > <fx:Style source="/com/tutorialspoint/client/Style.css"/> <fx:Script> <![CDATA[ protected function reportEvent(event:MouseEvent):void { var target:String = event.target.id; var currentTarget:String = event.target.id; var eventPhase: String; if(event.target is Button){ var button:Button = event.target as Button; target = button.label + " Button"; } else if(event.target is HGroup){ var hGroup:HGroup = event.target as HGroup; target = hGroup.id + " HGroup"; }else if(event.target is Panel){ var panel:Panel = event.target as Panel; target = panel.id + " Panel"; } if(event.currentTarget is Button){ var button1:Button = event.currentTarget as Button; currentTarget = button1.label + " Button"; }else if(event.currentTarget is HGroup){ var hGroup1:HGroup = event.currentTarget as HGroup; currentTarget = hGroup1.id + " HGroup"; }else if(event.currentTarget is Panel){ var panel1:Panel = event.currentTarget as Panel; currentTarget = panel1.id + " Panel"; } var eventPhaseInt:uint = event.eventPhase; if(eventPhaseInt == EventPhase.AT_TARGET){ eventPhase = "Target"; } else if(eventPhaseInt == EventPhase.BUBBLING_PHASE){ eventPhase = "Bubbling"; }else if(eventPhaseInt == EventPhase.CAPTURING_PHASE){ eventPhase = "Capturing"; } reports.text += " Target: " + target + "\n currentTarget: " + currentTarget + "\n Phase: " + eventPhase + "\n----------\n"; } ]]> </fx:Script> <s:BorderContainer width="630" height="480" id="mainContainer" styleName="container"> <s:VGroup width="100%" height="100%" gap="10" horizontalAlign="center" verticalAlign="middle"> <s:Label id="lblHeader" text="Event Handling Demonstration" fontSize="40" color="0x777777" styleName="heading"/> <s:Panel id="parentPanel" title="Main Parent" click="reportEvent(event)" width="500" height="100" includeInLayout="true" visible="true"> <s:layout> <s:VerticalLayout gap="10" verticalAlign="middle" horizontalAlign="center"/> </s:layout> <s:HGroup id="mainHGroup" click="reportEvent(event)"> <s:Button label="Click Me" click="reportEvent(event)"/> </s:HGroup> </s:Panel> <s:Panel id="reportPanel" title="Events" width="500" height="230"> <mx:Text id="reports" /> </s:Panel> </s:VGroup> </s:BorderContainer> </s:Application> 准备好所有更改后,让我们以正常模式编译和运行应用程序,就像在 Flex - 创建应用程序中一样 章节。 如果一切顺利,您的应用程序,这将产生以下结果:[在线试用] |
请发表评论