第一帧上代码:
/* sxl001 http://sxl001.07dns.com qq: 285510591 */
//============= 初始区 ================================
stop();
//----- 全屏与隐菜单区
fscommand("fullscreen", true);
fscommand("showmenu", false);
//----- 变量区
/* total_num 记录输入总数 | txtLong_num 输入字符长度 | num_array 记录输入的所有数
如输入 119 时:
total_num=119 | txtLong_num=3 | num_array=[001,002,003,....]
*/
var total_num:Number = 0;
var txtLong_num:Number = 0;
var num_array:Array = [];
//=======================================================
//============= 按钮与声音区 ============================
var startMp3:Sound = new Sound();
startMp3.attachSound("start");
startMp3.start();
var loopMp3:Sound = new Sound();
loopMp3.attachSound("loop");
startMp3.onSoundComplete = function() {
startMp3.start();
};
start_mc.onRollOver = function() {
_sound();
this.play();
};
start_mc.onPress = function() {
Submit();
};
start_mc.onRollOut = function() {
this.play();
};
quit_btn.onRollOver = function() {
_sound();
};
quit_btn.onPress = function() {
fscommand("quit", true);
};
//----- 文本区
Selection.setFocus(input_txt);
input_txt.maxChars = 4; // 控制4位(最多9999人)足够用了
input_txt.restrict = "0-9";
input_txt.border = true;
input_txt.borderColor = 0xFF00FF;
//==========================================================
//============= 函数区 =====================================
//----- 提交
function Submit() {
if (input_txt.text != "" && input_txt.text.substr(0, 1) != "0") {
total_num = Number(input_txt.text);
txtLong_num = input_txt.text.length;
Distribution(input_txt.text);
startMp3.stop();
play();
}
Key.removeListener(keyListener);
}
//-------- num_array存贮从0到最大数值
function Distribution(str:String) {
var long:Number = str.length;
var maxNum:Number = Number(str);
for (var i:Number = 1; i<=maxNum; i ) {
var l:Number = String(i).length;
var zha:Number = long-l;
switch (zha) {
case 0 :
num_array.push(i);
break;
case 1 :
num_array.push("0" i);
break;
case 2 :
num_array.push("00" i);
break;
case 3 :
num_array.push("000" i);
break;
}
}
}
//----- 数组乱序
function randomArray(Target_array:Array) {
Target_array.sort(function () {
return Math.round(Math.random()) ? 1 : -1;
});
}
//----- 按钮声音
function _sound() {
var btnS:Sound = new Sound();
btnS.attachSound("btnSound");
btnS.start();
}
//----- 回车键提交
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == "13") {
if (input_txt.text != "" && input_txt.text.substr(0, 1) != "0") {
total_num = Number(input_txt.text);
txtLong_num = input_txt.text.length;
Distribution(input_txt.text);
startMp3.stop();
_root.play();
Key.removeListener(keyListener);
}
}
};
Key.addListener(keyListener);
//================================================
第二帧上代码:
stop();
//============= 初始区 ===========================
//------ 加点投影效果
import flash.filters.DropShadowFilter;
var d_filtersropShadowFilter = new DropShadowFilter(5, 45, 0x336633, 80, 8, 8);
//------ 数组乱序
randomArray(num_array);
//------ loop声音
loopMp3.start();
loopMp3.onSoundComplete = function() {
loopMp3.start();
};
/*
如输入 119 时:
total_num=119 | txtLong_num=3 | num_array=[001,....]
randomNum 停止工作时显示未位上的数字相同的一组文本框(0~3) | C_array 用于删除已抽的号码函数 |
getNo_array 存贮获取的当前一组文本中的数字 | jieguo_mcY0 弹出的显示已抽号的窗口的初始y坐标
*/
var randomNum:Number, C_array:Array = [], getNo_array:Array = [], jieguo_mcY0:Number = jieguo_mc._y;
var kO:Boolean = true;
total_txt.text = "参与选号总数是: " total_num;
//=====================================================
//============= 函数区 ===============================
//------ 根据第一帧上输入的数值复制文本框个数与各位数上的数量
this.createEmptyMovieClip("main", 0);
body();
function body() {
for (var i:Number = 0; i<txtLong_num; i ) {
for (var j:Number = 0; j<4; j ) {
main["m" i j] = main.attachMovie("cell", "m" i j, main.getNextHighestDepth(), {_x:i*80, _y:-j*85});
main["m" i j].v = true;
main["m" i j].filters = [d_filters];
//main["m" i j].num 决定再次升到顶端时其中的数值从数组num_array中进行取值的位置
main["m" i j].num = j;
main["m" i j].t.text = num_array[j].toString().substr(i, 1);
Rolling(main["m" i j]);
}
}
}
//------- 文本框居中排列
PosiMain();
function PosiMain() {
main._x = Stage.width/2-main._width/2;
main._y = Stage.height/2-40;
}
//------- 滚动函数
function Rolling(target:MovieClip) {
target.onEnterFrame = function() {
if (this.v) {
this._y = 40;
if (this._y>=80) {
this.num = 4;
if (this.num>total_num) {
this.num = Number(this._name.substr(2, 1));
}
this.t.text = num_array[Number(this.num)].toString().substr(this._name.substr(1, 1), 1);
this._y = -255;
}
} else {
deleCell();
}
};
}
main.setMask(mask_mc);
//------- 停止滚动和显示结果区
function deleCell() {
for (var i in main) {
// 如果文本框未位上的数字与停止按钮给出的数字不同时就被删除
if (main._name.substr(2, 1) != randomNum) {
main.t.text = "";
main._visible = false;
main.removeMovieClip();
delete main.onEnterFrame;
} else {
// 如果文本框未位上的数字与停止按钮给出的数字相同时就作为显示对象
if (main._y != 0) {
main._y = (0-main._y)/10;
} else {
//--- 删除num_array中已抽的号码
C_array.push(main);
if (C_array.length == txtLong_num) {
var n = main.num;
getNo_array.push(num_array[n]);
jieguo_mc.t.text = "";
for (var Index:Number = (getNo_array.length-1); Index>=0; Index--) {
jieguo_mc.t.text = "第" (Index 1) "次抽取的号码是: " getNo_array[Index] "\n";
}
var tw1 = new mx.transitions.Tween(jieguo_mc, ’_y’, mx.transitions.easing.Back.easeOut, jieguo_mcY0, Stage.height-jieguo_mc._height, 1, true);
num_array.splice(n, 1);
delete main.onEnterFrame;
}
}
}
}
}
//===================================================
//============= 按钮与声音区 ========================
stop_mc.t.text = "停止";
reSet_mc.t.text = "再选";
// 控制按钮切换变量
stop_mc.onOff = true;
reSet_mc.onOff = false;
stop_mc.onRollOver = function() {
_sound();
this.play();
};
stop_mc.onPress = function() {
if (this.onOff) {
// randomNum决定哪组文本框被保留或被删除
randomNum = random(4);
loopMp3.stop();
C_array = [];
for (var i in main) {
//main.v决定执行停止滚动和显示结果区
main.v = false;
}
reSet_mc.onOff = true;
this.onOff = false;
kO = false;
}
};
stop_mc.onRollOut = function() {
this.play();
};
reSet_mc.onRollOver = function() {
_sound();
this.play();
};
reSet_mc.onPress = function() {
if (this.onOff) {
loopMp3.start();
for (var i in main) {
delete main.onEnterFrame;
main.removeMovieClip();
}
body();
stop_mc.onOff = true;
this.onOff = false;
kO = true;
}
};
reSet_mc.onRollOut = function() {
this.play();
};
jieguo_mc.Press_mc.onRollOver = function() {
_sound();
};
jieguo_mc.Press_mc.onPress = function() {
var tw2 = new mx.transitions.Tween(jieguo_mc, ’_y’, mx.transitions.easing.Back.easeOut, jieguo_mc._y, jieguo_mcY0, 1, true);
};
//----- 回车键控制
var keyObj:Object = new Object();
keyObj.onKeyDown = function() {
if (Key.getCode() == Key.ENTER) {
switch (kO) {
case true :
// randomNum决定哪组文本框被保留或被删除
randomNum = random(4);
loopMp3.stop();
C_array = [];
for (var i in main) {
//main.v决定执行停止滚动和显示结果区
main.v = false;
}
reSet_mc.onOff = true;
stop_mc.onOff = false;
kO = false;
break;
case false :
loopMp3.start();
for (var i in main) {
delete main.onEnterFrame;
main.removeMovieClip();
}
body();
stop_mc.onOff = true;
reSet_mc.onOff = false;
kO = true;
break;
}
}
};
Key.addListener(keyObj);
//===========================================
Flash教程:模拟幸运号抽奖机
各位看官记得要回帖哦!教学中经常要用到抽号,名称随便取的,也叫“幸运号”吧。做了一个,不是很成熟,有那么点效果而已,仅供新手参考(程序中运用了一些常用的基础语法),抛砖引玉而已。