文章搜索:
打开支付宝首页搜索“510617664”,即可领红包
  首页--> 计算机--> FLASH教程
 
为Alert组件加上响应功能
http://www.xxqqss.com 学习轻松网 点击量:5573
 
 这一段时间在倒腾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/

附件: alert.rar

来源:闪吧论坛  作者:korpton


打印】 【关闭
免责声明 :本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请发送fiyeadwyv@163.com
最热门点击排行
 
版权所有 2006-2021:学习轻松网 Copyright http://www.xxqqss.com All rights reserved 浙ICP备14013707号-1
广告联系电话: 13958357030 联系QQ:9792414 工具条下载