本站常年招开AS3培训,一对一教学。联系QQ:8286659

发一个即插即用的loading经典代码

站站长制作的很多flash都是用的这个loading,不需要你人工制作loading,不需要你编写任何as代码,只要你简单的复制+粘贴就OK了,很方便。

演示:http://www.taoshaw.com

使用方法:
1.在flash中的第一桢上,按F9弹出动作面板,然后复制以下代码到动作面板里,一个flash的loading就完成了。
2.注意:不管你的flash有多少桢,第一桢一定要留空,就是一个“空白关键桢”,然后把这段代码加上去。第二桢才做flash的主体内容。

代码:

stop();
var rect1:MovieClip = createRectangle1(150, 3, 0x0099FF); //进度条的颜色
var rect2:MovieClip = createRectangle2(152, 5, 0x000000);
rect1._x = (Stage.width - rect1._width) / 2;
rect1._y = (Stage.height - rect1._height) / 2;
rect2._x = (Stage.width - rect2._width) / 2;
rect2._y = (Stage.height - rect2._height) / 2;
onEnterFrame = function () {
rect1._width = _root.getBytesLoaded() / _root.getBytesTotal() * 150;
if (_root.getBytesLoaded() == _root.getBytesTotal()) {
rect1.removeMovieClip();
rect2.removeMovieClip();
delete rect1;
delete rect2;
delete createRectangle1;
delete createRectangle2;
delete onEnterFrame;
play();
}
};
function createRectangle1(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
scope = (scope == undefined) ? this : scope;
var depth:Number = scope.getNextHighestDepth();
var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
mc.beginFill(color);
mc.lineTo(0,height);
mc.lineTo(width, height);
mc.lineTo(width, 0);
mc.lineTo(0,0);
return mc;
}
function createRectangle2(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
scope = (scope == undefined) ? this : scope;
var depth:Number = scope.getNextHighestDepth();
var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
mc.lineStyle(color,0x000033); //进度条边框的颜色
mc.moveTo(0, 0);
mc.lineTo(0, height);
mc.lineTo(width, height);
mc.lineTo(width, 0);
mc.lineTo(0, 0);
return mc;
}


留言
用户名:   密码:   注册?
验证码 * 请输入验证码(不想注册?OK,请直接输入用户名、验证码、内容即可。密码处请留空)