教你7步实现flex自定义Event及参数传递
Flex应用开发过程中如需要灵活的在不同组件(如A与B,父与子)之间响应事件,传递参数等功能时就会使用自定义事件(Event)机制,下面通过一个事例分七步,通过自定义Event和EventDispatcher两种机制实现事件交互和参数传递;
事例描述: 有一个父亲“parentApp.mxml”有两个儿子“comBrotherA.mxml”和"comBrotherB.mxml",新年降至,两个儿子为表孝心分别给他们老爸存入(事件)一笔过节费(事件参数),并通知老爸我存钱进去了,老爸在收到两个儿子的钱后汇总后同时告诉(事件)两个儿子钱我已收到总数(事件参数)是多少...
1、第一步:引入自定义注册事件参数传递扩展类(来自网络)
package myeventhelper
{
//自定义注册事件参数传递扩展类
public class EventArgExtend
{
public function EventArgExtend()
{
}
public static function create(f:Function,...arg):Function //动态参数创建
{
var F:Boolean = false;
var _f:Function = function(e:*,..._arg)
{
_arg = arg;
if(!F)
{
F = true;
_arg.unshift(e);
}
f.apply(null,_arg);
};
return _f;
}
public static function toString():String
{
return "Class JEventDelegate";
}
}
}
2、第二步:自定义事件触发类:
package myeventhelper
{
import flash.events.EventDispatcher;
import mx.core.UIComponent;
//自定义事件触发类
public class MyEventDispatcher extends EventDispatcher
{
private static var _instance:MyEventDispatcher;
public static const EXEC_PARENT_METHOD:String="ExecParentMethod"; //执行Parent方法
public static function getI
相关文档:
-----------------ex4_01_solution------------------Creating an event and dispatching the event object
<s:Application ...
creationComplete="employeeService.send()">
会触发:
<!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
& ......
flash.system. Capabilities.os;//客户端系统版本
flash.system.Capabilities.language;//客户端语言
flash.system.Capabilities.version;//播放器版本
flash.system.Capabilities.playerType;//播放器类型
flash.system.Capabilities.screenResolutionX&Y;//分辨率 ......
在flex开发环境中编写as3代码是很方便的,借助flex开发环境代码都有自动提示功能,但是在做flash游戏的时候,在涉及到对话框的时候,我遇到一个很棘手的问题,就是在美工用flash cs布局好了的界面,我在界面上命名了实例(如textfield类型 var nameText:String),在导出这个类(guestDialog)的时候(这个类继承自MovieClip ......
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/04/adding-animations-and-effects-to-flex-tool-tips/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertic ......
<![CDATA[
Flex中的键盘事件
要在Flex中响应键盘输入,只需注册keyDown事件即可。
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" keyDown="OnKeyDown(event)">
<mx:Script>
......