1. Declare a custom Event that extends Event and have some properties for data transfer purpose.
2. Declare the custom Event in component/application's metadata block
3. In the declared component/application, dispatch the custom event under specific circumstance.
4. Use the component in outter component/application and generate the event handler.
5. Get the data stored in event object.
Eg.
1. Application domain(VOTest.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" xmlns:components="components.*" minWidth="955" minHeight="600" preinitialize="initApp(event)"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> <fx:XML id="employeeXML" source="data/employees.xml"/> </fx:Declarations> <fx:Script> <![CDATA[ import event.ShowPreview; import mx.collections.ArrayCollection; import mx.controls.Alert; import vo.Employee; public var employee:Employee; [Bindable] public var employeeList:ArrayCollection = new ArrayCollection(); public function initApp(event:Event):void{ for each(var emp:Object in employeeXML.children()){ employee = new Employee(); employee.firstName = emp.firstName; employee.lastName = emp.lastName; employee.city = emp.city; employeeList.addItem(employee); } } protected function employeedisplay1_showPreviewHandler(event:ShowPreview):void{ previewLabel.text = (event as ShowPreview).employee.firstName + " "; previewLabel.text += (event as ShowPreview).message; previewLabel.visible = true; } ]]> </fx:Script> <s:VGroup> <components:EmployeeDisplay employeeList="{employeeList}" showPreview="employeedisplay1_showPreviewHandler(event)"/> <s:Label text="Employee Preview" id="previewLabel" visible="false"/> </s:VGroup> </s:Application>
2. Component Domain(EmployeeDisplay.mxml)
<?xml version="1.0" encoding="utf-8"?> <s:Group 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="278" height="552" preinitialize="initApp(event)"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Metadata> [Event(name="showPreview", type="event.ShowPreview")] </fx:Metadata> <fx:Script> <![CDATA[ import event.ShowPreview; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.events.CalendarLayoutChangeEvent; import vo.Employee; [Bindable] public var employeeList:ArrayCollection; private var employee:Employee; public function initApp(event:Event):void{ for each(var emp:Employee in employeeList){ employee = new Employee(); employee.firstName = emp.firstName; employee.lastName = emp.lastName; employee.city = emp.city; } } protected function button1_clickHandler(event:MouseEvent):void{ var eventObject:ShowPreview = new ShowPreview("showPreview", employeeDropDownList.selectedItem, employeeTextArea.text); this.dispatchEvent(eventObject); } ]]> </fx:Script> <s:VGroup> <s:DropDownList id="employeeDropDownList" dataProvider="{employeeList}" labelField="firstName"/> <s:TextArea id="employeeTextArea"/> <s:Button label="Preview" click="button1_clickHandler(event)"/> </s:VGroup> </s:Group>
3. Custom Event(ShowPreview.as)
package event { import flash.events.Event; import vo.Employee; public class ShowPreview extends Event { public var employee:Employee; //Data for transfer public var message:String; //Data for transfer public function ShowPreview(type:String, employee:Employee, message:String) { super(type); //type info: can be Event.CLICK or custom event type defined in <metadata> this.employee = employee; this.message = message; } } }
4. Value Object(Employee.as)
package vo { [Bindable] public class Employee { public var firstName:String; public var lastName:String; public var id:String; public var title:String; public var email:String; public var managerID:String; public var department:String; public var location:String; public var phone:String; public var directDial:String; public var deskLocation:String; public var city:String; public var state:String; public var countryCode:String; public var postalCode:String; public var hireDate:Date; public var evaluation:int; public function Employee() {} public function createFullName():String{ return this.firstName + " " + this.lastName; } } }
相关推荐
MyBatis-Flex: 一个优雅的 MyBatis 增强框架。很轻量,MyBatis-Flex 整个框架只依赖 MyBatis,再无其他任何第三方依赖。只增强,MyBatis-Flex 支持 CRUD、分页查询、多表查询、批量操作,但不丢失 MyBatis 原有的...
### Flex:事件的流转控制 #### 一、事件机制概览 在Flex中,事件机制是一种非常核心且灵活的功能,它允许开发人员有效地管理和响应应用程序内的各种交互行为。Flex的应用程序是基于事件驱动架构的,这意味着大...
@ twilio-labs / plugin-flex Twilio CLI插件可与进行交互该插件为添加了功能,以便在本地开发,构建和部署;...指令 twilio flex:plugins:start twilio flex:plugins:build 构建您的Flex插件,并创建
在本文中,我们将探讨如何使用Adobe Flex来实现柱状专题图层,这是一种在地图上以柱状图形式展示统计数据的有效方法,特别适合于比较和分析各类统计数据。柱状专题图或直方图专题图在地理信息系统中非常常见,它们...
### Flex:获得鼠标所在位置的经纬度坐标 在Flex开发中,经常需要处理与地理位置相关的功能,例如地图应用、地理信息系统(GIS)等。获取鼠标所在位置的经纬度坐标是这些应用的基础。本文档详细介绍了如何在Flex...
在前端开发中,Flex布局(Flexible Box)是一种用于创建弹性盒模型的CSS3模块,它极大地增强了网页布局的灵活性。而当内容超出容器时,滚动条的出现是必不可少的。在Flex布局中,我们可以有几种不同的方法来实现滚动...
Flex:Web报表引擎——MyReport 2.3.0.0 + 免Flex开发集成版 --新增功能:重新设计表达式解析引擎,支持更多函数,运算符,支持运算符函数递归嵌套 --新增功能:重新设计表达式编辑器 --新增功能:新增字体颜色设置...
Flex:Web报表引擎——MyReport 2.3.6.0 + 免Flex开发集成版 release 2.3.6.0 --新增功能:报表编辑器支持打开/报表本地文件功能 --新增功能:单元格垂直合并 --新增功能:报表编辑器,标题行支持单个和多个单元格...
在FLEX 里,解决FLEX 占用内存一直不减,无法清除的问题
NULL 博文链接:https://hcty31.iteye.com/blog/1122729
在Flex编程中,动态画直线是一项基础且实用的技术,尤其在构建交互式用户界面或图形应用时。本文将深入探讨如何使用Flex实现这个功能,并基于提供的"Flex 动态画直线"主题,解释核心概念和步骤。 首先,让我们了解...
flex: 1, items: [me.ReservationDate] }, { flex: 1, items: [me.ReviewDate] }, { flex: 1, items: [me.edtKeyword] }, { flex: 1, layout: { type: 'hbox' }, items: [me.btnSearch, me.btnClear...
在Linux中,执行以下步骤可以安装flex: 1. **解压**:首先,使用`tar`命令解压缩文件: ```bash tar -zxvf flex-2.5.39.tar.gz ``` 2. **进入目录**:进入解压后的目录: ```bash cd flex-2.5.39 ``` 3. *...
New:2.0版本支持Flex SDK 4.1,建议使用Adobe Flash Builder 4开发环境。 详情参考:http://blog.csdn.net/hunkcai/archive/2010/07/13/5732866.aspx Web报表引擎: Web上的良好的打印解决方案,WinForm的打印预览...
* 用Adobe Flash Builder 4开发环境打开,用Flex SDK 4.1进行编译 * 内有报表样式定义说明 * 内有Demo工程参考,使用MyReport * 不提供MyReport源码,提供swc组件(类似dll) * 只需少量工作就能把MyReport整合,获得...
D:\下载\Fuji Flexa软件介绍(中文版).rarD:\下载\Fuji Flexa软件介绍(中文版).rarD:\下载\Fuji Flexa软件介绍(中文版).rarD:\下载\Fuji Flexa软件介绍(中文版).rarD:\下载\Fuji Flexa软件介绍(中文版).rarD:\下载\...
this.addEventListener(Event.ADDED_TO_STAGE, handleAddToStage); } private function handleAddToStage(event:Event):void { ExternalInterface.addCallback("parseUrlParams", parseUrlParams); } ...
<title>The Complete Guide to Flex 2 and ActionScript 3.0 <title>Programming Flex 2 (Programming) <title>Adobe Flex 2: Training from the Source ``` 这个XML文件的结构十分简单。主要节点是`...
Written for Java developers beginning to use Flex, Flex on Java shows how to use Flex alongside existing Java applications, and how to integrate Flex using familiar server-side technologies such as ...
在Flex 4中,数据绑定是一项强大的特性,它允许开发者创建动态、响应式的用户界面,无需编写大量的事件处理代码。本教程将深入讲解如何在Flex 4中对自定义类进行数据绑定,通过一个实际的MXML文件和AS文件示例来阐述...