联欢晚会上要抽取人的号码,所以就做了这个。
代码:
//定义抽取号码范围
var hao:Array = new Array();
for(var i:int = 1;i<1001;i++){
hao.push(i)
}
var num:int = 0;
var add_num:int = 0;
//抽取的号分类
var xu_array:Array = ["一", "二", "三"];
//随机显示被抽号码
var timer = new Timer(400,0);
timer.addEventListener(TimerEvent.TIMER,timerHandler);
function timerHandler(event:Event):void{
//取得hao数组的长度,里现在是1000
num = Math.floor(Math.random()*hao.length);
show_txt.text = hao[num];
}
timer.start();
//开始抽取号码
start_btn.addEventListener(MouseEvent.CLICK,yaohaoF);
function yaohaoF(event:MouseEvent):void{
add_num++;
result_txt.text+="幸运号"+xu_array[add_num-1]+":"+Math.floor(Math.random()*hao.length)+"\r";
//关键在这里,把上面抽出的号码从数组中删除,它就不会再出现了
hao.splice(num, 1);
//如果已经抽出三个奖,就停止
if (add_num>3) {
timer.stop();
show_txt.text = "此轮完成,下一轮?";
result_txt.text ="";
start_btn.visible = false;
next_btn.visible = true;
}
}
next_btn.addEventListener(MouseEvent.CLICK,nextF);
function nextF(event:MouseEvent):void{
timer.start();
start_btn.visible = true;
next_btn.visible = false;
add_num = 0;
}
界面:
功能添加和源程序修改:http://etthink.5d6d.com/thread-606-1-1.html
源程序下载:抽奖源程序下载
原创文章如转载,请注明:转载自且行资源 [ http://www.qiexing.com/ ]
本文链接地址:http://www.qiexing.com/post/769.html

