xml|加载
放假了,没多少事,发个模糊、缓冲、顺序加载、XML等的混合运用简单实例,作品粗糙,给我等新手们参考,抛砖引玉吧,如果你觉得可以一定记得要顶帖。
第一帧上加载进度显示:
stop();
load_txt.selectable = false;//动态文本用于显示加载进度
onEnterFrame = function () {
var l:Number = _root.getBytesLoaded();
var t:Number = _root.getBytesTotal();
var p:Number = Math.round(l/t)*100;
load_txt.text = "loading "+p+"%";//动态文本显示加载进度
if (l == t) {
delete onEnterFrame;
this.play();
}
};
第二帧用于导入外部XML,XML中存贮了图片地址,图片名称等数据。
stop();
Title_txt.selectable = false;
System.useCodepage = true;
var _imgPathArray:Array = new Array();//存贮图片地址的数组
var _imgTitleArray:Array = new Array();//存贮图片名称的数组
var _imgBgColorArray:Array = new Array();存贮图片背景颜色的数组
var _xml:XML = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = function(success) {
if (success) {
var xmllength:Number = this.firstChild.childNodes.length;
for (var i:Number = 0; i<xmllength; i++) {
_imgPathArray.push(this.firstChild.childNodes.attributes.path);//地址
_imgTitleArray.push(this.firstChild.childNodes.attributes.Title);//图片名称
_imgBgColorArray.push(this.firstChild.childNodes.attributes.BgColor);//背景颜色
play();
}
} else {
stop();
}
};
_xml.load("imgs/imgxml.xml");
第三帧上是主要AS帧:
stop();
//...初始化区...................................................................................
var img_mc:MovieClip = this.createEmptyMovieClip("img_mc", this.getNextHighestDepth());//用于加载的空MovieClip
img_mc._x = 10;
img_mc._y = 10;
this.createTextField("Title_txt", this.getNextHighestDepth(), 0, 5, 600, 20);//用于显示图片名称的文本
Title_txt.selectable = false;
Title_txt.background = true;
Title_txt.backgroundColor = 0xF8B929;
Title_txt.align = "center";
Title_txt.autoSize = true;
var my_color:Color = new Color(bg_mc);//背景颜色
//...点小图出大图...........................................................................................
//复制10个装载小图的MovieClip
for (var i:Number = 0; i<_imgPathArray.length; i++) {
this["small_mc"+i] = attachMovie("small_mc", "small_mc"+i, i);
this["small_mc"+i]._x = 38+53*i;//排列好位置
this["small_mc"+i]._y = 374;
}
//小图点击出大图函数
var _hitsound:Sound = new Sound();
_hitsound.attachSound("But");
function hit_small_img() {
for (var i:Number = 0; i<_imgPathArray.length; i++) {
_root["small_mc"+i].onPress = function() {
_hitsound.start();
//取得被点小图名称的数字部分字符串.............................
var str_to_num:Number = new Number(this._name.substr(8, 2));
k = str_to_num;//传值给下方小图两边的小三角形左右按钮
//执行出大图函数
runBigImag(str_to_num);
//标题
Title_txt.text = _imgTitleArray[str_to_num];
Title_txt_x = Stage.width/2-Title_txt._width/2;//图片标题的位置居中
img_mc_tween(Title_txt, -100, Title_txt_x);//图片标题缓动
};
}
}
//导入小图函数
loadsmallimg();
function loadsmallimg() {
loadID = setInterval(loadsmall, 100);
}
var i:Number = 0;
function loadsmall() {
loadMovie(_imgPathArray, _root["small_mc"+i]);
var l:Number = _root["small_mc"+i].getBytesLoaded();
var t:Number = _root["small_mc"+i].getBytesTotal();
if (l == t) {
if (_root["small_mc"+i]._width != 50) { //小图顺序导入
_root["small_mc"+i]._width = 50;
_root["small_mc"+i]._height = 37;
i++;
}
}
if (l == undefined) {//如果完成导入时,删除loadID,再执行小图点击出大图函数
clearInterval(loadID);
hit_small_img();
}
}
//......................................
//...出大图函数.............
function runBigImag(Num:Number) {
_loadImg.loadClip(_imgPathArray[Num], img_mc);
//背景颜色
my_color.setRGB(_imgBgColorArray[Num]);
}
//..............................................................................................
//...滤镜区........................................................................................
//缓冲滤镜
var _sound:Sound = new Sound();
_sound.attachSound("sound");
import mx.transitions.Tween;
import mx.transitions.easing.*;
function img_mc_tween(target:MovieClip, xstart:Number, xend:Number) {
var myTween:Tween = new Tween(target, "_x", Strong.easeOut, xstart, xend, 1, true);
_sound.start();
}
//模糊滤镜
import flash.filters.*;
function img_mc_filters() {
var tempNum:Number = 60;
onEnterFrame = function () {
if (tempNum != 0) {
tempNum -= 5;//逐渐模糊
img_mc.filters = [new BlurFilter(tempNum, 0, 3)];
} else {
delete onEnterFrame;
}
};
}
//.................................................................................................
//...导入图片区...........................................................................
var _loadImg:MovieClipLoader = new MovieClipLoader();
var _loadObj:Object = new Object();
_loadObj.onLoadInit = function(target_mc:MovieClip, Num:Number) {
target_mc._width = 580;
target_mc._height = 360;
target_mc._x = Stage.width/2-target_mc._width/2;
target_mc._y = 5;
img_mc_tween(img_mc, Stage.width, img_mc._x);
img_mc_filters();
};
_loadImg.addListener(_loadObj);
_loadImg.loadClip(_imgPathArray[0], img_mc);
//标题
Title_txt.text = _imgTitleArray[0];
Title_txt._x = Stage.width/2-Title_txt._width/2;
//........................................................................................
//...按钮区.......................................
leftarrow_mc.gotoAndStop(1);
rightarrow_mc.gotoAndStop(1);
leftarrow_mc.onRollOver = function() {
this.play();
};
rightarrow_mc.onRollOver = function() {
this.play();
};
leftarrow_mc.onRollOut = function() {
this.gotoAndStop(1);
};
rightarrow_mc.onRollOut = function() {
this.gotoAndStop(1);
};
var k:Number = 0;
leftarrow_mc.onPress = function() {
if (k>0) {
k--;
Title_txt.text = _imgTitleArray[k];
Title_txt_x = Stage.width/2-Title_txt._width/2;//图片标题的位置居中
img_mc_tween(Title_txt, -100, Title_txt_x);//图片标题缓动
_loadImg.loadClip(_imgPathArray[k], img_mc);
img_mc_tween(img_mc, Stage.width, img_mc._x);
img_mc_filters();
_hitsound.start();
}
};
rightarrow_mc.onPress = function() {
if (k<_imgPathArray.length) {
k++;
Title_txt.text = _imgTitleArray[k];
Title_txt_x = Stage.width/2-Title_txt._width/2;//图片标题的位置居中
img_mc_tween(Title_txt, -100, Title_txt_x);//图片标题缓动
_loadImg.loadClip(_imgPathArray[k], img_mc);
img_mc_tween(img_mc, Stage.width, img_mc._x);
img_mc_filters();
_hitsound.start();
}
};
//................................................
imgxml.xml:
<?xml version="1.0" encoding="utf-8" ?>
<imglist>
<pic path="imgs/1.jpg" Title="欧宝001" BgColor="0x080D11"></pic>
<pic path="imgs/2.jpg" Title="欧宝002" BgColor="0x0A0D14"></pic>
<pic path="imgs/3.jpg" Title="欧宝003" BgColor="0x191E24"></pic>
<pic path="imgs/4.jpg" Title="欧宝004" BgColor="0x151C26"></pic>
<pic path="imgs/5.jpg" Title="欧宝005" BgColor="0x06090E"></pic>
<pic path="imgs/6.jpg" Title="奔驰001" BgColor="0x0D0918"></pic>
<pic path="imgs/7.jpg" Title="奔驰002" BgColor="0x120F18"></pic>
<pic path="imgs/8.jpg" Title="奔驰003" BgColor="0x030007"></pic>
<pic path="imgs/9.jpg" Title="奔驰004" BgColor="0x37363C"></pic>
<pic path="imgs/10.jpg" Title="碧波天际之间" BgColor="0x27497A">
</imglist>
/////////////////
源文件:点击这里下载源文件