Flash CS制作幸运大抽奖gif动画特效教程
程序员文章站
2022-06-13 14:49:33
这篇教程是向脚本之家的朋友介绍利用Flash CS制作幸运大抽奖gif动画特效方法,教程制作出来的效果很不错,方法也很简单,只供菜鸟们参考。推荐到脚本之家,喜欢的朋友一起来学习吧... 14-12-29...
好久未来这了,刚好这两天没什么事,又做了一个抽奖的小东东玩玩,只供菜鸟们参考,老鸟们见笑了。
照惯例上主要代码:
复制代码
代码如下:stop();
/*
@sxl
@qq:285510591
@http://sxl001.129hb.com
@2009.12.20
*/
system.usecodepage =true;
// title_mc:标题 | gong_mc:显示中奖 | msg_mc:显示所有中奖和未中奖情况
title_mc.cacheasbitmap=true;
gong_mc.cacheasbitmap=true;
gong_mc.y=1000;
msg_mc.cacheasbitmap=true;
msg_mc.x=-1000;
// 下列是声音效果数据
var mousw_over_sound:over=new over(),rect_up_sound:move=new move(),rect_down_soundown=new down(),_win:win=new win();
// gong_array:奖品名 | balls:各个号码 | hit_ball_array:已抽号码
var gong_array:array =[],balls:array =[],hit_ball_array:array =[],move_gong_mc:boolean=true,move_msg_mc:boolean;
// 以下是内部设置奖品
var data_str:string ="环保手提袋|罗技|电磁炉|显示器|移动硬盘|掌上游戏机|手机|3g手机|九阳豆浆机|电动剃须刀|雅顿香水|数码相机|闪存盘|离子电视|消毒柜|松下洗衣机|电磁炉|电饭煲|电压力锅|光波炉|搅拌机|榨汁机|电茶壶|咖啡机|自动烹饪锅|紫砂煲|空调|吸油烟机|取暖器|加湿器";
gong_array =data_str.split("|");
randomarray(gong_array);
/* 以下注释部分是从外部文本中导入奖品数据
var loadernum:urlloader = new urlloader();
configurelistenersnum(loadernum);
var urlnum:string ="data/奖品.txt";
var requestnum:urlrequest=new urlrequest(urlnum);
loadernum.load(requestnum);
function configurelistenersnum(dispatcher:ieventdispatcher):void {
dispatcher.addeventlistener(event.complete, completehnum);
dispatcher.addeventlistener(ioerrorevent.io_error, ioerrorhandler);
}
function completehnum(event:event):void {
gong_array =event.target.data.split("|");
randomarray(gong_array);
event.target.removeeventlistener(event.complete, completehnum);
event.target.removeeventlistener(event.complete, ioerrorhandler);
}
function ioerrorhandler(event:ioerrorevent):void {
dele_balls_seleabled();
chakan_mc.buttonmode =false;
chakan_mc.removeeventlistener(mouseevent.mouse_over ,onmouse_click);
chakan_mc.removeeventlistener(mouseevent.mouse_down ,onmouse_click);
chakan_mc.removeeventlistener(mouseevent.mouse_out ,onmouse_click);
gong_mc._txt.text="请检查数据";
gong_mc.ball._txt.text="-_-";
gong_mc.addeventlistener(event.enter_frame,move_gong_mc_rect);
gong_mc.close_btn.enabled=false;
gong_mc.close_btn.removeeventlistener(mouseevent.mouse_down,oncloseshowgong);
event.target.removeeventlistener(event.complete, completehnum);
event.target.removeeventlistener(event.complete, ioerrorhandler);
}
*/
for (var i:uint =0; i<30; i++) {
this["ball" + i].cacheasbitmap=true;
this["ball" + i].gotoandstop("one");
balls.push(this["ball" + i]);
msg_mc["m" + i].ball_mc.gotoandstop("one");
if (i<9) {
this["ball"+i]._txt.text="0"+uint(i+1);
msg_mc["m"+i].ball_mc._txt.text="0"+uint(i+1);
} else {
this["ball"+i]._txt.text=""+uint(i+1);
msg_mc["m"+i].ball_mc._txt.text=""+uint(i+1);
}
msg_mc["m"+i].t.text="等 待 抽 奖";
this["ball"+i].i=i;
this["ball"+i].buttonmode =true;
this["ball"+i].mousechildren=false;
this["ball" + i].addeventlistener(mouseevent.mouse_over ,onmouse_click);
this["ball" + i].addeventlistener(mouseevent.mouse_down ,onmouse_click);
this["ball" + i].addeventlistener(mouseevent.mouse_out ,onmouse_click);
//......
}
chakan_mc.buttonmode =true;
chakan_mc.mousechildren=false;
chakan_mc.addeventlistener(mouseevent.mouse_over ,onmouse_click);
chakan_mc.addeventlistener(mouseevent.mouse_down ,onmouse_click);
chakan_mc.addeventlistener(mouseevent.mouse_out ,onmouse_click);
function onmouse_click(sxl:mouseevent) {
var target:movieclip =sxl.currenttarget as movieclip;
var target_name:string =target.name.substr(0,1);
switch (sxl.type) {
case "mouseover" :
mousw_over_sound.play();
switch (target_name) {
case "b" :
getbitmapfilter(target);
break;
case "c" :
settxtcolor(target.t,0xffffff);
break;
}
break;
case "mouseout" :
switch (target_name) {
case "b" :
target.filters =null;
break;
case "c" :
settxtcolor(target.t,0xffff00);
break;
}
break;
case "mousedown" :
switch (target_name) {
case "b" :
dele_balls_seleabled();
target.removeeventlistener(mouseevent.click ,onmouse_click);
target.gotoandstop("two");
settxtcolor(target._txt);
var index:string =target.i;
hit_ball_array.push(target);
var str:uint =uint(target.name.substr(4));
if (str<9) {
gong_mc.ball._txt.text="0"+uint(str+1);
} else {
gong_mc.ball._txt.text=""+uint(str+1);
}
gong_mc._txt.text=gong_array[index];
gong_mc.addeventlistener(event.enter_frame,move_gong_mc_rect);
rect_up_sound.play();
msg_mc["m" + index].ball_mc.play();
msg_mc["m"+index].t.text=gong_array[index];
settxtcolor(msg_mc["m"+index].t,0xffff00);
settxtcolor(msg_mc["m" + index].ball_mc._txt);
break;
case "c" :
target.t.text="移开中奖结果";
if (math.abs(gong_mc.y-300)<10) {
move_gong_mc=false;
gong_mc.addeventlistener(event.enter_frame,move_gong_mc_rect);
}
move_msg_mc=!move_msg_mc;
msg_mc.addeventlistener(event.enter_frame,show_msg_mc);
rect_up_sound.play();
break;
}
break;
}
}
//
function show_msg_mc(sxl:event) {
if (move_msg_mc) {
var dis_up:number =(354-sxl.target.x)/5;
sxl.target.x+=dis_up;
if (math.abs(dis_up)<1) {
sxl.target.x=354;
sxl.target.removeeventlistener(event.enter_frame,show_msg_mc);
}
} else {
var dis_down:number =(1800-sxl.target.x)/5;
sxl.target.x+=dis_down;
if (math.abs(dis_down)<10) {
chakan_mc.t.text="查看中奖结果";
sxl.target.x=-1000;
sxl.target.removeeventlistener(event.enter_frame,show_msg_mc);
}
}
}
// 删除所有数字按钮功能
function dele_balls_seleabled() {
for (var i:uint =0; i<balls.length; i++) {
var a:movieclip =balls;
a.buttonmode =false;
a.removeeventlistener(mouseevent.mouse_over ,onmouse_click);
a.removeeventlistener(mouseevent.mouse_down ,onmouse_click);
a.removeeventlistener(mouseevent.mouse_out ,onmouse_click);
}
}
// 启用可用数字按钮功能
function show_balls_seleabled(a_arr:array,b_arr:array) {
var a_array:array=a_arr,b_array:array=b_arr;
for (var i:uint =0; i<a_array.length; i++) {
var a:movieclip =a_array;
a.buttonmode =true;
a.mousechildren=false;
a.addeventlistener(mouseevent.mouse_over ,onmouse_click);
a.addeventlistener(mouseevent.mouse_down ,onmouse_click);
a.addeventlistener(mouseevent.mouse_out ,onmouse_click);
}
for (var j:uint =0; j<b_array.length; j++) {
var b:movieclip =b_array[j];
b.filters =null;
b.buttonmode =false;
b.removeeventlistener(mouseevent.mouse_over ,onmouse_click);
b.removeeventlistener(mouseevent.mouse_down ,onmouse_click);
b.removeeventlistener(mouseevent.mouse_out ,onmouse_click);
}
}
gong_mc.close_btn.addeventlistener(mouseevent.mouse_down,oncloseshowgong);
function oncloseshowgong(sxl:mouseevent) {
rect_down_sound.play();
gong_mc.addeventlistener(event.enter_frame,move_gong_mc_rect);
}
function move_gong_mc_rect(sxl:event) {
if (move_gong_mc) {
var dis_up:number =(300-sxl.target.y)/5;
sxl.target.y+=dis_up;
if (math.abs(dis_up)<1) {
_win.play();
sxl.target.gold.play();
sxl.target.y=300;
sxl.target.removeeventlistener(event.enter_frame,move_gong_mc_rect);
move_gong_mc=false;
}
} else {
var dis_down:number =(1000-sxl.target.y)/5;
sxl.target.y+=dis_down;
if (math.abs(dis_down)<10) {
sxl.target.y=1000;
sxl.target.removeeventlistener(event.enter_frame,move_gong_mc_rect);
move_gong_mc=true;
show_balls_seleabled(balls,hit_ball_array);
}
}
}
function randomarray(target_array:array):void {
target_array.sort(function () {
return math.round(math.random()) ? 1 : -1;
});
}
function settxtcolor(_txt:textfield,color:uint=0x666666) {
var my_textformat:textformat =new textformat();
my_textformat.color =color;
_txt.defaulttextformat = my_textformat;
_txt.settextformat(my_textformat);
}
//... 投影
function getbitmapfilter(_mc:movieclip) {
var color:number = 0x000000;
var angle:number = 45;
var alpha:number = 0.8;
var blurx:number = 8;
var blury:number = 8;
var distance:number = 15;
var strength:number = 0.65;
var inner:boolean = false;
var knockout:boolean = false;
var quality:number = bitmapfilterquality.high;
var mydropshadowfilterropshadowfilter= new dropshadowfilter(distance,angle,color,alpha,blurx,blury,strength,quality,inner,knockout);
_mc.filters =[mydropshadowfilter];
}
以上就是flash cs制作幸运大抽奖gif动画特效教程,希望大家喜欢!
/*
@sxl
@qq:285510591
@http://sxl001.129hb.com
@2009.12.20
*/
system.usecodepage =true;
// title_mc:标题 | gong_mc:显示中奖 | msg_mc:显示所有中奖和未中奖情况
title_mc.cacheasbitmap=true;
gong_mc.cacheasbitmap=true;
gong_mc.y=1000;
msg_mc.cacheasbitmap=true;
msg_mc.x=-1000;
// 下列是声音效果数据
var mousw_over_sound:over=new over(),rect_up_sound:move=new move(),rect_down_soundown=new down(),_win:win=new win();
// gong_array:奖品名 | balls:各个号码 | hit_ball_array:已抽号码
var gong_array:array =[],balls:array =[],hit_ball_array:array =[],move_gong_mc:boolean=true,move_msg_mc:boolean;
// 以下是内部设置奖品
var data_str:string ="环保手提袋|罗技|电磁炉|显示器|移动硬盘|掌上游戏机|手机|3g手机|九阳豆浆机|电动剃须刀|雅顿香水|数码相机|闪存盘|离子电视|消毒柜|松下洗衣机|电磁炉|电饭煲|电压力锅|光波炉|搅拌机|榨汁机|电茶壶|咖啡机|自动烹饪锅|紫砂煲|空调|吸油烟机|取暖器|加湿器";
gong_array =data_str.split("|");
randomarray(gong_array);
/* 以下注释部分是从外部文本中导入奖品数据
var loadernum:urlloader = new urlloader();
configurelistenersnum(loadernum);
var urlnum:string ="data/奖品.txt";
var requestnum:urlrequest=new urlrequest(urlnum);
loadernum.load(requestnum);
function configurelistenersnum(dispatcher:ieventdispatcher):void {
dispatcher.addeventlistener(event.complete, completehnum);
dispatcher.addeventlistener(ioerrorevent.io_error, ioerrorhandler);
}
function completehnum(event:event):void {
gong_array =event.target.data.split("|");
randomarray(gong_array);
event.target.removeeventlistener(event.complete, completehnum);
event.target.removeeventlistener(event.complete, ioerrorhandler);
}
function ioerrorhandler(event:ioerrorevent):void {
dele_balls_seleabled();
chakan_mc.buttonmode =false;
chakan_mc.removeeventlistener(mouseevent.mouse_over ,onmouse_click);
chakan_mc.removeeventlistener(mouseevent.mouse_down ,onmouse_click);
chakan_mc.removeeventlistener(mouseevent.mouse_out ,onmouse_click);
gong_mc._txt.text="请检查数据";
gong_mc.ball._txt.text="-_-";
gong_mc.addeventlistener(event.enter_frame,move_gong_mc_rect);
gong_mc.close_btn.enabled=false;
gong_mc.close_btn.removeeventlistener(mouseevent.mouse_down,oncloseshowgong);
event.target.removeeventlistener(event.complete, completehnum);
event.target.removeeventlistener(event.complete, ioerrorhandler);
}
*/
for (var i:uint =0; i<30; i++) {
this["ball" + i].cacheasbitmap=true;
this["ball" + i].gotoandstop("one");
balls.push(this["ball" + i]);
msg_mc["m" + i].ball_mc.gotoandstop("one");
if (i<9) {
this["ball"+i]._txt.text="0"+uint(i+1);
msg_mc["m"+i].ball_mc._txt.text="0"+uint(i+1);
} else {
this["ball"+i]._txt.text=""+uint(i+1);
msg_mc["m"+i].ball_mc._txt.text=""+uint(i+1);
}
msg_mc["m"+i].t.text="等 待 抽 奖";
this["ball"+i].i=i;
this["ball"+i].buttonmode =true;
this["ball"+i].mousechildren=false;
this["ball" + i].addeventlistener(mouseevent.mouse_over ,onmouse_click);
this["ball" + i].addeventlistener(mouseevent.mouse_down ,onmouse_click);
this["ball" + i].addeventlistener(mouseevent.mouse_out ,onmouse_click);
//......
}
chakan_mc.buttonmode =true;
chakan_mc.mousechildren=false;
chakan_mc.addeventlistener(mouseevent.mouse_over ,onmouse_click);
chakan_mc.addeventlistener(mouseevent.mouse_down ,onmouse_click);
chakan_mc.addeventlistener(mouseevent.mouse_out ,onmouse_click);
function onmouse_click(sxl:mouseevent) {
var target:movieclip =sxl.currenttarget as movieclip;
var target_name:string =target.name.substr(0,1);
switch (sxl.type) {
case "mouseover" :
mousw_over_sound.play();
switch (target_name) {
case "b" :
getbitmapfilter(target);
break;
case "c" :
settxtcolor(target.t,0xffffff);
break;
}
break;
case "mouseout" :
switch (target_name) {
case "b" :
target.filters =null;
break;
case "c" :
settxtcolor(target.t,0xffff00);
break;
}
break;
case "mousedown" :
switch (target_name) {
case "b" :
dele_balls_seleabled();
target.removeeventlistener(mouseevent.click ,onmouse_click);
target.gotoandstop("two");
settxtcolor(target._txt);
var index:string =target.i;
hit_ball_array.push(target);
var str:uint =uint(target.name.substr(4));
if (str<9) {
gong_mc.ball._txt.text="0"+uint(str+1);
} else {
gong_mc.ball._txt.text=""+uint(str+1);
}
gong_mc._txt.text=gong_array[index];
gong_mc.addeventlistener(event.enter_frame,move_gong_mc_rect);
rect_up_sound.play();
msg_mc["m" + index].ball_mc.play();
msg_mc["m"+index].t.text=gong_array[index];
settxtcolor(msg_mc["m"+index].t,0xffff00);
settxtcolor(msg_mc["m" + index].ball_mc._txt);
break;
case "c" :
target.t.text="移开中奖结果";
if (math.abs(gong_mc.y-300)<10) {
move_gong_mc=false;
gong_mc.addeventlistener(event.enter_frame,move_gong_mc_rect);
}
move_msg_mc=!move_msg_mc;
msg_mc.addeventlistener(event.enter_frame,show_msg_mc);
rect_up_sound.play();
break;
}
break;
}
}
//
function show_msg_mc(sxl:event) {
if (move_msg_mc) {
var dis_up:number =(354-sxl.target.x)/5;
sxl.target.x+=dis_up;
if (math.abs(dis_up)<1) {
sxl.target.x=354;
sxl.target.removeeventlistener(event.enter_frame,show_msg_mc);
}
} else {
var dis_down:number =(1800-sxl.target.x)/5;
sxl.target.x+=dis_down;
if (math.abs(dis_down)<10) {
chakan_mc.t.text="查看中奖结果";
sxl.target.x=-1000;
sxl.target.removeeventlistener(event.enter_frame,show_msg_mc);
}
}
}
// 删除所有数字按钮功能
function dele_balls_seleabled() {
for (var i:uint =0; i<balls.length; i++) {
var a:movieclip =balls;
a.buttonmode =false;
a.removeeventlistener(mouseevent.mouse_over ,onmouse_click);
a.removeeventlistener(mouseevent.mouse_down ,onmouse_click);
a.removeeventlistener(mouseevent.mouse_out ,onmouse_click);
}
}
// 启用可用数字按钮功能
function show_balls_seleabled(a_arr:array,b_arr:array) {
var a_array:array=a_arr,b_array:array=b_arr;
for (var i:uint =0; i<a_array.length; i++) {
var a:movieclip =a_array;
a.buttonmode =true;
a.mousechildren=false;
a.addeventlistener(mouseevent.mouse_over ,onmouse_click);
a.addeventlistener(mouseevent.mouse_down ,onmouse_click);
a.addeventlistener(mouseevent.mouse_out ,onmouse_click);
}
for (var j:uint =0; j<b_array.length; j++) {
var b:movieclip =b_array[j];
b.filters =null;
b.buttonmode =false;
b.removeeventlistener(mouseevent.mouse_over ,onmouse_click);
b.removeeventlistener(mouseevent.mouse_down ,onmouse_click);
b.removeeventlistener(mouseevent.mouse_out ,onmouse_click);
}
}
gong_mc.close_btn.addeventlistener(mouseevent.mouse_down,oncloseshowgong);
function oncloseshowgong(sxl:mouseevent) {
rect_down_sound.play();
gong_mc.addeventlistener(event.enter_frame,move_gong_mc_rect);
}
function move_gong_mc_rect(sxl:event) {
if (move_gong_mc) {
var dis_up:number =(300-sxl.target.y)/5;
sxl.target.y+=dis_up;
if (math.abs(dis_up)<1) {
_win.play();
sxl.target.gold.play();
sxl.target.y=300;
sxl.target.removeeventlistener(event.enter_frame,move_gong_mc_rect);
move_gong_mc=false;
}
} else {
var dis_down:number =(1000-sxl.target.y)/5;
sxl.target.y+=dis_down;
if (math.abs(dis_down)<10) {
sxl.target.y=1000;
sxl.target.removeeventlistener(event.enter_frame,move_gong_mc_rect);
move_gong_mc=true;
show_balls_seleabled(balls,hit_ball_array);
}
}
}
function randomarray(target_array:array):void {
target_array.sort(function () {
return math.round(math.random()) ? 1 : -1;
});
}
function settxtcolor(_txt:textfield,color:uint=0x666666) {
var my_textformat:textformat =new textformat();
my_textformat.color =color;
_txt.defaulttextformat = my_textformat;
_txt.settextformat(my_textformat);
}
//... 投影
function getbitmapfilter(_mc:movieclip) {
var color:number = 0x000000;
var angle:number = 45;
var alpha:number = 0.8;
var blurx:number = 8;
var blury:number = 8;
var distance:number = 15;
var strength:number = 0.65;
var inner:boolean = false;
var knockout:boolean = false;
var quality:number = bitmapfilterquality.high;
var mydropshadowfilterropshadowfilter= new dropshadowfilter(distance,angle,color,alpha,blurx,blury,strength,quality,inner,knockout);
_mc.filters =[mydropshadowfilter];
}
上一篇: 3DMAX 灯光技术基础教程详解
下一篇: MAYA制作中山舰模型之动画绑定篇