|

- 帖子
- 87
- 积分
- 27
- 技术分
- 10
- 来自
- 广东深圳
- 在线时间
- 62 小时
- 注册时间
- 2006-6-20
|
1#
发表于 2007-1-6 12:35
| 只看该作者
为Alert组件加上响应功能!~
这一段时间在倒腾flex,很少玩flash了,今天翻到有人发表
<< ScrollBar,List,Alert组件的使用及实例>>, 原文:http://space.flash8.net/bbs/thread-309057-1-3.html
看到后面的Alert组件只有show一下,事实上他还有响应部分,比如,用户点了确定按钮之后又该
如何呢?
这里就针对这个我添加一下,画蛇添足一下!:-)
我可以先下载那个alert.fla,我是在这个基础上添加的!
后面我也提供了一个修改后的附件!
好了,正题:
第一步,添加个Label,和一个Button
命名:
Label : MsgBox_lbl
Button : CallAlert_btn
第二步:添加CallAlert_btn按钮代码:- CallAlert_btn.onRelease = function(){
- _global.style.modalTransparency = 40; //设定全局透明度
- Alert.yesLabel = "Yes"; //Alert确定按钮文字,事实上也可以是:"确定","OK","行,就这样",一类的
- Alert.noLabel = "No";
- Alert.buttonWidth = 75; //如果是 "行,就这样" 那么铵钮是不是要大一点呢
- Alert.show ("点击一下", "", Alert.YES | Alert.NO, _root, alClicar, "prueba", Alert.OK);
- //这里是用 alClicar 对象来响应的
- };
复制代码 第三步:添加响应对象- alClicar = new Object ();
- alClicar = function (evento)
- {
- if (evento.detail == Alert.YES) //用户点了yes按钮
- {
- MsgBox_lbl.text = "你点击了OK按钮";
- // 这里也可以添加一些其它的动作..
- }
- else if (evento.detail == Alert.NO) //用户点了No按钮
- {
- MsgBox_lbl.text = "你点击了No按钮";
- // 这里也可以添加一些其它的动作..
- }
- };
复制代码 以上就可以实现响应了!
最后完整的代码应该是这样的:- import mx.controls.Alert
- CallAlert_btn.onRelease = function(){
- _global.style.modalTransparency = 40;
- Alert.yesLabel = "Yes";
- Alert.noLabel = "No";
- Alert.buttonWidth = 75;
- Alert.show ("点击一下", "", Alert.YES | Alert.NO, _root, alClicar, "prueba", Alert.OK);
- };
- //
- alClicar = new Object ();
- alClicar = function (evento)
- {
- if (evento.detail == Alert.YES)
- {
- MsgBox_lbl.text = "你点击了OK按钮";
- }
- else if (evento.detail == Alert.NO)
- {
- MsgBox_lbl.text = "你点击了No按钮";
- }
- };
- /*
- var lObj:Object = new Object();//创建侦听器对象
- Alert.show("表单填写不正确,请重新填写", "",Alert.OK | Alert.CANCEL, this, lObj);
- */
- stop();
复制代码 ----------------
blog: http://www.oiasoft.com/blog/
web: http://www.celesteteam.com/
[ 本帖最后由 korpton 于 2007-1-7 00:55 编辑 ] |
-
-
alert.rar (133.1 KB)
http://www.oiasoft.com
http://www.celesteteam.com/ |
|