Adobe Air & Adobe Flex & ActionScript & Mobile Dev & HTML5 & RIA & User Experience
在 Flex/Flash 项目中,richmediaplus.utils.AlertUtils 比 Flex.Alert 更容易控制和修改 Alert Message 的信息分类,信息内容,能对整个项目的 Alert Message 做到统一化处理。AlertUtils 完成于 2006-2007 之间,最近整理文档,所以拿出来分享。
先看一下 Flex/Flash 自带的 Alert:
Alert.show(text:String = "", title:String = "", flags:uint = 0x4, parent:Sprite = null, closeHandler:Function = null, iconClass:Class = null, defaultButtonFlag:uint = 0x4):Alert
Alert Message 直接写在 Flex/Flash 的项目中,对于 Message 的不同性质,不同内容,不同parent,不同icon,不同 button 首选项…都要进行逐一的控制,而每次可能都会常常填写相同的 Message 内容 和 Message 标题。多的事情看起来就很讨厌,麻烦的事情更加让人不想去做。若遇到问题需要对 Message 进行修改,Alert 有多少我们就要改多少,而且时不时会有不小心遗漏的现象的问题出现。如果一开始就对 Alert Message 进行统一有效的管理,尽可能的简洁 Alert Message 的方式,在后面的项目开发过程中,将会有事半功倍的效果。
下面开始对 Alert Message 进行修改和设计。
为了达到每次修改 Message Content 而不用重新编译 Flex/Flash,我们将 Message 以 XML 的形式存在,而 Flex/Flash 要做的就是读取 message.xml,然后通过直接传入 Node String(‘error.richmediaplus.login’) 的方式,将相对应的 XML 信息体现在画面上。如果需要对 Message 进行相关的新增,修改,删除时,只对 message.xml 修改即可。
既然要用到 Node String ,就要在设计上与程序员有个统一的共识,目前认为『Message 分类』.『项目模块』.『详细信息』是比较好的选择之一。『Message 分类』可以对 Message 的性质进行统一管理,而且对其出现相应的 iconClass 进行统一设计。
『Message 分类』
『项目模块』
注册模块(register)的『详细信息』
登录模块(login)的『详细信息』
因此整个 message.xml 设计如下:
<?xml version="1.0" encoding="UTF-8"?> <message> <title>Message Title</title> <info> <common> <test>这是替换字1: [0],这是替换字2: [1],这是替换字3: [2]</test> </common> <search> <resultNone>您所输入的关键字 [0] 查询不到相关信息!</resultNone> </search> </info> <attention> <register> <passwordRule>密码长度6~16个字符,字母区分大小写</passwordRule> <passwordRepeatRule>请重复输入一次相同的登录密码</passwordRepeatRule> </register> </attention> <question> <user> <del>确定删除帐号?</del> </user> </question> <error> <login> <passwordWrong>对不起,您的密码不正确! </passwordWrong> </login> <undefined>不明的错误原因。</undefined> </error> </message>
XML 内容除了上面所说的『Message 分类』.『项目模块』.『详细信息』之外,还有个 title 的 NODE 和比较特殊的“[0][1][2]”等。一个项目的 Alert Message Title 一般来说比较固定,所以也可以设置在 XML 里,不用每次都要去敲,而比较特殊的“[0][1][2]”是 Message 内容的替代标识,适用于 Message 内容相同但主体不同的例子,如上面的 XML 的 info.search.resultNone 都是反应查询不到关键字的意思,但关键字每次可能不一样,我们可以及时对用户查询不到的关键字进行替换,而不用整个 Message 重新写过,只要传入相应的参数组合即可。
Alert Message 的形式
因此 AlertUtils 有 3 个 public static function
3 个不同的方法,基本可以覆盖所有需要 Alert Message 的方式,他们对应的button 首选项也是不一样,如 AlertOKMsg 的 button 首选项是 Alert.OK,而 AlertYesNoMsg 的 button 首选项是 Alert.NO。
看看,到目前为止
Alert.show(text:String = "", title:String = "", flags:uint = 0x4, parent:Sprite = null, closeHandler:Function = null, iconClass:Class = null, defaultButtonFlag:uint = 0x4):Alert
分析一下,只剩下3个不确定的参数
其中 parent 一般默认为 Application,因此只剩下 text 和 closeHandler。
所以默认的 AlertUtils 相关 Alert Message 方法的参数设计为
//message 为 Message Node String,如'error.richmediaplus.login'。 //closeHandler 为 Alert Message 关闭的方法,默认为 null。 //parent 为 事件区域,默认为 Application。 //defaultButtonFlag 为 AlertUtils 对应方法的 button 首选项,如 AlertOKMsg 的默认 button 首选项是 Alert.OK,而 AlertYesNoMsg 的默认button 首选项是 Alert.NO。 //title 为 Alert Message Title,默认为 message.xml 中的 title。 //parameters 为可选参数数组,对相应的[0][1][2][3]...进行替换。 AlertUtils.AlertXXXMsg(message:String, closeHandler:Function = null, parent:Sprite = null, defaultButtonFlag:uint = Alert.NO, title:String = "", parameters:Array = null)
所以,当需要呼出密码规则不符的警告时,只需 AlertUtils.AlertOKMsg(“attention.register.passwordRule”)就可返回“密码长度6~16个字符,字母区分大小写”的信息;若关键字 richmediaplus 搜索不到相应信息,只需 AlertUtils.AlertOKMsg(“info.search.resultNone”, ['richmediaplus']),就可以返回“您所输入的关键字richmediaplus查询不到相关信息!”
具体详见
AlertUtils Demo
Related posts:
Leave a reply
Pingbacks & Trackbacks
richmediaplus.controls.Pager : : 9RIA.Com 天地会博客聚合
七月 14th, 2010 at 12:10 上午
AlertUtils 更名为 AlertUtil : : 9RIA.Com 天地会博客聚合
七月 30th, 2010 at 9:05 下午
將 Box2D Alchemy WCK 打包為 SWC 類別庫 : : 9RIA.Com 天地会博客聚合
七月 8th, 2011 at 12:01 下午