AS3.0新手必读--影片Loading
原代码说明:
1帧:
/*********************************
AS3.0 LOADING CODE
www.mhhf.net
MAGIC WING STUDIO
BY 2007-09-01
**********************************/
stop();
stage.scaleMode=StageScaleMode.NO_SCALE;
//设置舞台属性不跟随播放器大小而改变
stage.showDefaultContextMenu=false;
//屏蔽右键菜单
stage.frameRate=30;
//设置帧频为30
var stageW=stage.stageWidth;
var stageH=stage.stageHeight;
//取得舞台宽和高
var loadclip:MovieClip=new MovieClip();
//创建LOADING MC loadclip
this.addChild(loadclip)
//添加loadclip到舞台
var txt=new TextField();
//创建文本文件 txt
txt.autoSize=TextFieldAutoSize.CENTER;
//文本文件自适应大小并且居中显示
txt.text="AS3.0 Loading...";
txt.textColor=0x000000;
//设置文本颜色
txt.selectable=false;
//文本设置为不可选
txt.x=stageW/2-txt.width/2;
txt.y=stageH/2-txt.height/2;
//设置本文件放置于舞台中央
loadclip.addChild(txt);
//将文本实例txt添加到loadclip
var stgb=new Sprite();
stgb.graphics.lineStyle(1,0x000000,1);
stgb.graphics.beginFill(0xff0000,.5);
//采用单色填充,红色透明50%(.5)
stgb.graphics.drawRect(0,0,200,10);
stgb.graphics.endFill();
stgb.x=stageW/2-stgb.width/2;
stgb.y=txt.y+txt.height+5;
loadclip.addChild(stgb)
//绘制进度条底色并且添加到loadclip
var stg=new Sprite();
stg.graphics.lineStyle(1,0x000000,.5);
stg.graphics.beginGradientFill(GradientType.LINEAR,[0xff0000,0xffff00],[100,100],[0,255]);
//采用渐变填充 红--黄
stg.graphics.drawRect(0,0,200,10);
stg.graphics.endFill();
stg.x=stageW/2-stg.width/2;
stg.y=txt.y+txt.height+5;
loadclip.addChild(stg)
//绘制进度条并且添加到loadclip
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,loading);
//添加进度监听
this.loaderInfo.addEventListener(Event.COMPLETE,loaded);
//添加进度完成监听
function loading(eve) {
var loadpre:int=eve.bytesLoaded/eve.bytesTotal*100;
txt.text="影片载入"+loadpre+" %";
stg.scaleX=loadpre/100;
}
//显示进度载入百分比-----
function loaded(eve) {
txt.text="影片载入完毕!";
if (framesLoaded == totalFrames) {
removeChild(this.getChildAt(0));
nextFrame();
}
}
//载入完毕清除LOADING MC 下一帧播放音乐
附件: AS3进度条代码.rar
1帧:
/*********************************
AS3.0 LOADING CODE
www.mhhf.net
MAGIC WING STUDIO
BY 2007-09-01
**********************************/
stop();
stage.scaleMode=StageScaleMode.NO_SCALE;
//设置舞台属性不跟随播放器大小而改变
stage.showDefaultContextMenu=false;
//屏蔽右键菜单
stage.frameRate=30;
//设置帧频为30
var stageW=stage.stageWidth;
var stageH=stage.stageHeight;
//取得舞台宽和高
var loadclip:MovieClip=new MovieClip();
//创建LOADING MC loadclip
this.addChild(loadclip)
//添加loadclip到舞台
var txt=new TextField();
//创建文本文件 txt
txt.autoSize=TextFieldAutoSize.CENTER;
//文本文件自适应大小并且居中显示
txt.text="AS3.0 Loading...";
txt.textColor=0x000000;
//设置文本颜色
txt.selectable=false;
//文本设置为不可选
txt.x=stageW/2-txt.width/2;
txt.y=stageH/2-txt.height/2;
//设置本文件放置于舞台中央
loadclip.addChild(txt);
//将文本实例txt添加到loadclip
var stgb=new Sprite();
stgb.graphics.lineStyle(1,0x000000,1);
stgb.graphics.beginFill(0xff0000,.5);
//采用单色填充,红色透明50%(.5)
stgb.graphics.drawRect(0,0,200,10);
stgb.graphics.endFill();
stgb.x=stageW/2-stgb.width/2;
stgb.y=txt.y+txt.height+5;
loadclip.addChild(stgb)
//绘制进度条底色并且添加到loadclip
var stg=new Sprite();
stg.graphics.lineStyle(1,0x000000,.5);
stg.graphics.beginGradientFill(GradientType.LINEAR,[0xff0000,0xffff00],[100,100],[0,255]);
//采用渐变填充 红--黄
stg.graphics.drawRect(0,0,200,10);
stg.graphics.endFill();
stg.x=stageW/2-stg.width/2;
stg.y=txt.y+txt.height+5;
loadclip.addChild(stg)
//绘制进度条并且添加到loadclip
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,loading);
//添加进度监听
this.loaderInfo.addEventListener(Event.COMPLETE,loaded);
//添加进度完成监听
function loading(eve) {
var loadpre:int=eve.bytesLoaded/eve.bytesTotal*100;
txt.text="影片载入"+loadpre+" %";
stg.scaleX=loadpre/100;
}
//显示进度载入百分比-----
function loaded(eve) {
txt.text="影片载入完毕!";
if (framesLoaded == totalFrames) {
removeChild(this.getChildAt(0));
nextFrame();
}
}
//载入完毕清除LOADING MC 下一帧播放音乐
附件: AS3进度条代码.rar