//加载需要使用的类
import mx.transitions.Tween;
import mx.transitions.easing.*;
//初始化各项参数
var _this:MovieClip = this;//进度条总长度
var bar_width:Number = 200;//进度条总高度
var bar_height:Number = 15;//细柱进度个数
var barItemNum:Number = 25;
//细柱进度宽度
var Item_width:Number = bar_width/barItemNum;//细柱进度间隔像素
var Item_xInterval:Number = 2;//细柱进度编码
var Item_Index:Number = 1;//是否已经结束
var MotionEnd:Boolean=false;//正在下载的编码
var NowDownIndex:Number;//细柱进度颜色
var barColor:Number = 0xffff00;//初始化效果库
var inEffect_lib:Array = new Array("Effect_fadeRandomMoveIn", "Effect_fadeIn", "Effect_XDropIn", "Effect_YDropIn",
"Effect_WindIn", "Effect_XElasticIn", "Effect_YElasticIn");
var outEffect_lib:Array = new Array("Effect_fadeRandomMoveOut", "Effect_fadeOut", "Effect_RandomXmove",
"Effect_RandomYmove", "Effect_WindOut", "Effect_ElasticYOut");//是否开启效果
var OpenEffect:Boolean = true;//开始效果编号
var StartEffect:Number = 4;//结束效果编号
var EndEffect:Number = 4;//是否开启随机效果
var RandomEffect:Boolean = true;
if (RandomEffect) {
var StartEffect:Number = random(inEffect_lib.length);
var EndEffect:Number = random(outEffect_lib.length);
}//是否显示进度数字
var ShowLoadNum:Boolean = true;
if (ShowLoadNum) {
var TF_format:TextFormat = new TextFormat();
TF_format.color = barColor;
TF_format.align = "right";
var progressNum:TextField = this.createTextField("progressNum", 2, -50, -2, 50, 20);
progressNum.selectable = false;
}//是否开启背景
var OpenBack:Boolean = true;//背景颜色
var BackColor:Number = 0x000000;
if (OpenBack) {
var progress_back:MovieClip = this.createEmptyMovieClip("progress_back", 1);
progress_back._x = -5;
progress_back._y = -2.5;
roundedRectangle(progress_back, bar_width+8, bar_height+5, 5, BackColor, 100);
if (ShowLoadNum) {
progress_back._x = -34;
roundedRectangle(progress_back, bar_width+36, bar_height+5, 5, BackColor, 100);
}
if (OpenEffect) {
var NewMC_tween:Object = new Tween(progress_back, "_xscale", Elastic.easeOut, 0, 100, 1, true);
}
}//函数
//创建进度条
function buildBar(loadedBytes, totalBytes) {
NowDownIndex = Math.round((loadedBytes/totalBytes)*barItemNum)+1;
progressNum.text = Math.round((loadedBytes/totalBytes)*100)+"%";
progressNum.setTextFormat(TF_format);
if (Item_IndexItem_Index) {
for (var i:Number = Item_Index; i
//定义结束触发函数
var finnishFuc:Number;
function onLoadFinnished() {
finnishFuc = setInterval(_this, "onAllOver", 50);
}
//结束效果完成后函数
//Back,Bounce,Elastic,None,Regular,Strong
function onAllOver() {
this[outEffect_lib[EndEffect]]();
Item_Index--;
if (Item_Index
//删除所有Interval
function clearAll(Void):Void {
var tmpId:Number = setInterval(function () {
}, 10);
while (--tmpId>0) {
clearInterval(tmpId);
}
}
//loading结束后函数
function onAllMoved() {
Item_Index = NowDownIndex;
if (Item_Index>=barItemNum) {
NewMC_tween.onMotionFinished = function() {
onLoadFinnished();
};
}
}
//================================================
var NewMC_tween:Object;
//退出效果
function Effect_fadeRandomMoveOut() {
var NewMC:MovieClip = this["rect_"+Item_Index];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeIn, 100, 0, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Strong.easeIn, NewMC._x, random(Stage.width)-this._x, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Strong.easeIn, NewMC._y, random(Stage.height)-this._y, 1, true);
}
function Effect_fadeOut() {
var NewMC:MovieClip = this["rect_"+Item_Index];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeIn, 100, 0, 1, true);
}
function Effect_RandomXmove() {
var NewMC:MovieClip = this["rect_"+Item_Index];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeIn, 100, 0, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Strong.easeIn, NewMC._x, random(Stage.width)-this._x, 1, true);
}
function Effect_RandomYmove() {
var NewMC:MovieClip = this["rect_"+Item_Index];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeIn, 100, 0, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Strong.easeIn, NewMC._y, random(Stage.height)-this._y, 1, true);
}
function Effect_WindOut() {
var NewMC:MovieClip = this["rect_"+Item_Index];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeIn, 100, 0, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Strong.easeIn, NewMC._x, NewMC._x-100, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Strong.easeIn, NewMC._y, NewMC._y-50, 1, true);
}
function Effect_ElasticYOut() {
var NewMC:MovieClip = this["rect_"+Item_Index];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeIn, 100, 0, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Elastic.easeIn, NewMC._y, random(Stage.height)-this._y, 1, true);
}
//进入效果
function Effect_fadeRandomMoveIn() {
for (var i:Number = Item_Index; i
//=============================================
//画圆角矩形
function roundedRectangle(target_mc:MovieClip, boxWidth:Number, boxHeight:Number,
cornerRadius:Number, fillColor:Number, fillAlpha:Number):Void {
with (target_mc) {
clear();
beginFill(fillColor, fillAlpha);
moveTo(cornerRadius, 0);
lineTo(boxWidth-cornerRadius, 0);
curveTo(boxWidth, 0, boxWidth, cornerRadius);
lineTo(boxWidth, cornerRadius);
lineTo(boxWidth, boxHeight-cornerRadius);
curveTo(boxWidth, boxHeight, boxWidth-cornerRadius, boxHeight);
lineTo(boxWidth-cornerRadius, boxHeight);
lineTo(cornerRadius, boxHeight);
curveTo(0, boxHeight, 0, boxHeight-cornerRadius);
lineTo(0, boxHeight-cornerRadius);
lineTo(0, cornerRadius);
curveTo(0, 0, cornerRadius, 0);
lineTo(cornerRadius, 0);
endFill();
}
}
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-loadingjiaocheng/2049.html