教你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
相关文档:
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate the DateTimeAxis class. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
......
-----------------ex4_01_solution------------------Creating an event and dispatching the event object
<s:Application ...
creationComplete="employeeService.send()">
会触发:
<!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
& ......
flex3 中的中文字体只支持有限的几种,要么嵌入字体,要么就使用这几种:
支持一些默认的英文字体,如Arial、Times New Roman、Courier New、Georgia、Verdana等。
支持的中文字体:宋体、华文楷体、华文细黑、华文仿宋、华文中宋。
Flex3 中即使客户端装了很多字体,能使用的也只能是上面几种字体,除非嵌入字体。
但是 ......
<?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 ......
flex嵌入到html:
用swfobject,下载的.js地址:http://www.adobe.com/devnet/activecontent/articles/devletter.html
在你的 HTML 页面头部<head>区嵌入这个脚本文件:<script type="text/javascript" src="swfobject.js"></script>
在你的 HTML 中写一个用来放 Flash 的容器,比如<div> ......