FLASH下雪代码.docx

上传人:b****8 文档编号:10742006 上传时间:2023-02-22 格式:DOCX 页数:4 大小:15.28KB
下载 相关 举报
FLASH下雪代码.docx_第1页
第1页 / 共4页
FLASH下雪代码.docx_第2页
第2页 / 共4页
FLASH下雪代码.docx_第3页
第3页 / 共4页
FLASH下雪代码.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

FLASH下雪代码.docx

《FLASH下雪代码.docx》由会员分享,可在线阅读,更多相关《FLASH下雪代码.docx(4页珍藏版)》请在冰豆网上搜索。

FLASH下雪代码.docx

FLASH下雪代码

Flash下要代码(as3.0)

1.新建一个文件夹,名为“纷扬的雪花”。

2.打开FLASH9.0或10.0都可,建立一个AS3.0的文件,大小550*400,保存在“纷扬的雪花”的文件夹里。

图层1添加一个背景图片,添加图层2,为AS层,选中第一帧打开动作面板,为其添加语句:

stage.frameRate=60;

varnum:

int=0;

stage.addEventListener(Event.ENTER_FRAME,enterFrameHandler);

functionenterFrameHandler(e:

Event):

void{

if(num<300){

addChild(newSnow());

num++;}

else{stage.removeEventListener(Event.ENTER_FRAME,enterFrameHandler);}}

3.新建一个ActionScript文件,名为“Snow.as”,保存在和源文件同名的“纷扬的雪花”文件夹里,在脚本区里复制如下代码:

package{

importflash.display.*;

importflash.events.*;

publicclassSnowextendsSprite{

publicvarradius:

Number;

publicvarangle:

Number;

publicvarspeed:

Number;

publicfunctionSnow(){

init();

addEventListener(Event.ENTER_FRAME,enterFrameHandler);

}

publicfunctioninit():

void{

radius=Math.random()*4;

angle=(Math.random()+0.5)*Math.PI/2;

speed=Math.random()+1;

x=Math.random()*550;

y=0;

alpha=Math.random();

graphics.clear();

graphics.beginFill(0xffffff);

graphics.drawCircle(0,0,radius);

graphics.lineTo(100,100);

}

publicfunctionenterFrameHandler(e:

Event):

void{

x+=speed*Math.cos(angle);

y+=speed*Math.sin(angle);

if(y>400||x<0||x>550){

init();

}}}}

4.保存一下,测试即可。

如要添加音乐可导入一首音乐,或者给主场的雪花脚本单独建一个影片剪辑,这样就能任意拖到任何一帧控制下雪与停止。

前提是Snow.as文件一定要和源文件放在同一文件夹里下雪代码:

1、文件—新建—ActionScript文件

2、输入以下代码(大小写字母不能改动):

package{

importflash.display.MovieClip;

importflash.events.*;

publicclassSNOWextendsMovieClip{

varspeedx:

Number=0;

varspeedy:

Number=0;

publicfunctionSNOW(){

speedx=5*Math.random()-0.5;

speedy=5*Math.random();

this.addEventListener(Event.ENTER_FRAME,Mot);

}

functionMot(e:

Event){

this.x+=speedx;

this.y+=speedy;

if(this.y>400){

init();

}

}

functioninit(){

this.y=0;

this.x=Math.random()*550;

}

}

}

3、以SNOW.as为文件名保存(不要改动)

4、文件—新建—Flash文件(ActionScript3.0)

5、将背景颜色设置为非白色(黑色等)

6、插入—新建—元件,类型为“影片剪辑”,名称为“水泡”(可任意命名),画一朵雪花。

7、右击“库”面板中的“水泡”元件,选择“链接”,在对话框中“链接”项中选择“为ActionScript导出”,“类”一栏中输入“SNOW”。

8、打开动作面板(窗口—动作),输入如下代码:

functionDisplaySNOW(){

for(vari:

int=0;i<150;i++){

varsnow:

SNOW=newSNOW();

this.addChild(snow);

snow.x=Math.random()*550;

snow.y=Math.random()*400;

snow.alpha=0.2+Math.random()*0.3;

varscale:

Number=0.4+Math.random();

snow.scaleX=snow.scaleY=scale;

}}

DisplaySNOW();

 

抓码王udgvsddd12976

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1