import mx.transitions.Tween;
import mx.transitions.easing.*;
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");
//是否开启效果"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);
}
//是否显示进度数字 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;
}
//是否开启背景 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);
}
}
//函数 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_Index<1) {
Item_Index = 1;
}
if (NowDownIndex>Item_Index) {
for (var i:Number = Item_Index; i<NowDownIndex; i++) {
var NewMC:MovieClip = this.createEmptyMovieClip("rect_"+i, 100+i);
NewMC._x = (i-1)*Item_width;
roundedRectangle(NewMC, Item_width-Item_xInterval, bar_height, 4, barColor, 100);
}
if (OpenEffect) {
this[inEffect_lib[StartEffect]]();
onAllMoved();
}
}
}
//定义结束触发函数NowDownIndex = Math.round((loadedBytes/totalBytes)*barItemNum)+1;
progressNum.text = Math.round((loadedBytes/totalBytes)*100)+"%";
progressNum.setTextFormat(TF_format);
if (Item_Index<1) {
Item_Index = 1;
}
if (NowDownIndex>Item_Index) {
for (var i:Number = Item_Index; i<NowDownIndex; i++) {
var NewMC:MovieClip = this.createEmptyMovieClip("rect_"+i, 100+i);
NewMC._x = (i-1)*Item_width;
roundedRectangle(NewMC, Item_width-Item_xInterval, bar_height, 4, barColor, 100);
}
if (OpenEffect) {
this[inEffect_lib[StartEffect]]();
onAllMoved();
}
}
}
var finnishFuc:Number;
function onLoadFinnished() {
finnishFuc = setInterval(_this, "onAllOver", 50);
}
//结束效果完成后函数function onLoadFinnished() {
finnishFuc = setInterval(_this, "onAllOver", 50);
}
//Back,Bounce,Elastic,None,Regular,Strong
function onAllOver() {
this[outEffect_lib[EndEffect]]();
Item_Index--;
if (Item_Index<1) {
progressNum.removeTextField();
var NewMC_tween:Object = new Tween(progress_back, "_xscale", Elastic.easeInOut, 100, 0, 1.5, true);
setInterval(clearAll, 10);
MotionEnd=true;
}
}
//删除所有Intervalfunction onAllOver() {
this[outEffect_lib[EndEffect]]();
Item_Index--;
if (Item_Index<1) {
progressNum.removeTextField();
var NewMC_tween:Object = new Tween(progress_back, "_xscale", Elastic.easeInOut, 100, 0, 1.5, true);
setInterval(clearAll, 10);
MotionEnd=true;
}
}
function clearAll(Void):Void {
var tmpId:Number = setInterval(function () {
}, 10);
while (--tmpId>0) {
clearInterval(tmpId);
}
}
//loading结束后函数var tmpId:Number = setInterval(function () {
}, 10);
while (--tmpId>0) {
clearInterval(tmpId);
}
}
function onAllMoved() {
Item_Index = NowDownIndex;
if (Item_Index>=barItemNum) {
NewMC_tween.onMotionFinished = function() {
onLoadFinnished();
};
}
}
//================================================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);
}
//进入效果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<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Strong.easeOut, random(Stage.width)-this._x, (i-1)*Item_width, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Strong.easeOut, random(Stage.height)-this._y, 0, 1, true);
}
}
function Effect_fadeIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeIn, 0, 100, 0.5, true);
}
}
function Effect_XDropIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Bounce.easeOut, NewMC._x+200, NewMC._x, 1, true);
}
}
function Effect_YDropIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Bounce.easeOut, -100, 0, 1, true);
}
}
function Effect_WindIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Strong.easeOut, NewMC._x-100, NewMC._x, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Strong.easeOut, NewMC._y-50, NewMC._y, 1, true);
}
}
function Effect_XElasticIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Elastic.easeOut, 100, NewMC._x, 1, true);
}
}
function Effect_YElasticIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Elastic.easeOut, -100, 0, 1, true);
}
}
//=============================================for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Strong.easeOut, random(Stage.width)-this._x, (i-1)*Item_width, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Strong.easeOut, random(Stage.height)-this._y, 0, 1, true);
}
}
function Effect_fadeIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeIn, 0, 100, 0.5, true);
}
}
function Effect_XDropIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Bounce.easeOut, NewMC._x+200, NewMC._x, 1, true);
}
}
function Effect_YDropIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Bounce.easeOut, -100, 0, 1, true);
}
}
function Effect_WindIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Strong.easeOut, NewMC._x-100, NewMC._x, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Strong.easeOut, NewMC._y-50, NewMC._y, 1, true);
}
}
function Effect_XElasticIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_x", Elastic.easeOut, 100, NewMC._x, 1, true);
}
}
function Effect_YElasticIn() {
for (var i:Number = Item_Index; i<=NowDownIndex; i++) {
var NewMC:MovieClip = this["rect_"+i];
NewMC_tween = new Tween(NewMC, "_alpha", Strong.easeOut, 0, 100, 1, true);
NewMC_tween = new Tween(NewMC, "_y", Elastic.easeOut, -100, 0, 1, true);
}
}
//画圆角矩形
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();
}
}
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();
}
}