当前位置:软件学习 > Flash >>

flash中loading效果实现代码

as3.0

在FLASH第一帧中加入以下代码。把主体内容移到第二帧即可。

// 设置loading的宽度,单位为像素
var loader_width = 150;
// 设置loading的高度,单位为像素
var loader_height = 4;
//设置loading的颜色值
var loading_color = 0x454545;
//创建两个图形
var my_loader_mc1 = createRectangle(this, loader_width, loader_height, loading_color, true);
var my_loader_mc2 = createRectangle(this, loader_width, loader_height, loading_color, false);
my_loader_mc1._x = (Stage.width - loader_width) / 2;
my_loader_mc1._y = (Stage.height - loader_height) / 2;
my_loader_mc2._x = my_loader_mc1._x;
my_loader_mc2._y = my_loader_mc1._y;
this.onEnterFrame = function ()
{
my_loader_mc1._width = _root.getBytesLoaded() / _root.getBytesTotal() * loader_width;
if (_root.getBytesLoaded() == _root.getBytesTotal()) {
my_loader_mc1.removeMovieClip();
my_loader_mc2.removeMovieClip();
delete my_loader_mc1;
delete my_loader_mc2;
delete this.onEnterFrame;
play();
}
};
function createRectangle(scope, w, h, color, is_fill)
{
var l = scope.getNextHighestDepth();
var _mc = scope.createEmptyMovieClip("mc_" + l, l);
with (_mc) {
lineStyle(0,color,100);
if (is_fill) {
beginFill(color,100);
}
lineTo(0,h);
lineTo(w,h);
lineTo(w,0);
lineTo(0,0);
endFill();
}
return _mc;
}
//第一帧默认为停止状态
stop();

as2

 代码如下 复制代码

//**********************************************************
//Copyright (C) 2006-2026
//黑白人动画工作室
//Email:syxu@3c800.com
//www.zzzyk.com
//**********************************************************
/*
FLASH开发通用模板
*/
//---------------------------------------------------------
stop();
_quality = "MEDIDU";
//"LOW"、"HIGH"、"BEST"
Stage.scaleMode = "noScale";
//"exactFit"、"showAll"、"noBorder"
fscommand("fullscreen", true);
//"quit"、"allowscale"、" showmenu "、"exec "、"trapallkeys"
//---------------------------------------------------------
//右键菜单版权信息和导航系统
rightmeun = new ContextMenu();
rightmeun.hideBuiltInItems();
rightmeun.customItems.push(new ContextMenuItem("rightmenu_item1", dj_menu0, false));
rightmeun.customItems.push(new ContextMenuItem("rightmenu_item2", dj_menu1, true));
rightmeun.customItems.push(new ContextMenuItem("rightmenu_item3", dj_menu2, false));
function dj_menu0() {
 //此处是你的代码...
}
function dj_menu1() {
 //此处是你的代码...
}
function dj_menu2() {
 //此处是你的代码...
}
_root.menu = rightmeun;
//---------------------------------------------------------
//自定义函数
function huanshu() {
 //此处是你的代码...
}
//---------------------------------------------------------
//纯AS的Loading...
function Draw(nam, de, d, al) {
 na = createEmptyMovieClip(nam, de);
 na.lineStyle(d, 0xFF6600, al);
 //颜色
 na._x = 200;
 //起始X
 na._y = 200;
 //起始Y
 na.lineTo(120, 0);
 //宽度
}
onEnterFrame = function () {
 var a = getBytesTotal();
 //总大小
 var b = getBytesLoaded();
 //已下载
 if (b<a) {
  Draw("b1", 1, 3, 20);
  //阴影
  Draw("b2", 2, 3, 100);
  //进度条
  b2._xscale = b/a*100;
  //进度条宽度百分比
 } else {
  delete onEnterFrame;
  b1.removeMovieClip();
  //删除进度条
  b2.removeMovieClip();
  play();
  //下载完成播放
 }
};
//调试时按Ctrl+B
//-------------------

补充:flash教程,动画技术
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,