首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > 交互式开发 >

关于Flash里面图片轮换的AS代码有关问题

2012-03-21 
关于Flash里面图片轮换的AS代码问题我要实现的:现在,我的fla文件里面有6个元件,我建立了一个bg.xml的文件

关于Flash里面图片轮换的AS代码问题
我要实现的:现在,我的fla文件里面有6个元件,我建立了一个bg.xml的文件用于保存和随时修改图片的路径,然后,把图片定时,一次加载到6个元件去,那6个元件每隔一段时间,就会同时更换一批图片。我在网上找了一个代码,但是,没搞懂怎么给6个元件加载图片的,谁能帮我说说- - 
不好意思,我是flash初学者,请给我注明,或者更改一下代码的相关位置吧- 

注:6个元件,定时更换图片,也就是同时更换6张,bg.xml里面保存的就是6张图片的路径。比如,30秒更换一次。

代码如下:

JScript code
var container:Array=new Array();var bgName:String;  //大图字符串var bgURL:URLRequest; var bgLoader:Loader;var bgcount:int=0;var masknum:Number=new Number();var timer:uint;var total:Number; var maskAry:Array=new Array(); //存放遮罩的数组var mask1:Mask1=new Mask1();var mask2:Mask2=new Mask2();var mask3:Mask3=new Mask3();var mask4:Mask4=new Mask4();var maks5:Mask5=new Mask5();addChild(mask1);addChild(mask2);addChild(mask3);addChild(mask4);addChild(maks5);maskAry=[mask1,mask2,mask3,mask4,maks5];for (var n=0;n<5;n++) {    maskAry[n].x=10000;    maskAry[n].y=0;}var imgXml:XML = new XML();var urlStr:String="bg.xml";var xmlLoader:URLLoader = new URLLoader();xmlLoader.load(new URLRequest(urlStr)); // 图片信息集记录文件xmlLoader.addEventListener(Event.COMPLETE, createArea);function createArea(e:Event):void {    imgXml = XML(xmlLoader.data);    total = imgXml.img.length();  //图片长度    //trace(total);    //numOfTotal = Math.ceil(total/numOfOneStep); //组数    showBigPic();//显示大图片    //showSmallPic(); //显示小图片}function showBigPic() {    for (var i:int=0; i<total; i++) {        container[i]=new bigPic();        addChild(container[i]);        bgName=imgXml.img[i].url;        bgURL=new URLRequest(bgName);        bgLoader=new Loader();        bgLoader.load(bgURL);        container[i].addChild(bgLoader);        bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,comPleteHandler);         function comPleteHandler(e:Event) {             var bp:Bitmap = e.currentTarget.content as Bitmap;             bp.height = stage.stageHeight;             bp.width =stage.stageWidth;         }        container[i].x=10000;        container[i].y=0;    }            bigPicShow();//大图片轮换显示}function bigPicShow() {    container[bgcount].x=0;    masknum=Math.floor(Math.floor(Math.random()*10)/2);    maskAry[masknum].x=0;    maskAry[masknum].gotoAndPlay(1);    //trace(masknum);    //trace(maskAry[masknum].currentFrame);    container[bgcount].mask=maskAry[masknum];    timer=setTimeout(tweenHandler,3000);}function tweenHandler() {    container[bgcount].x=10000;    container[bgcount].mask=null;    maskAry[masknum].x=10000;    bgcount++;    if (bgcount>=total) {        bgcount=0;    }    bigPicShow();}


[解决办法]
不懂,帮你顶一下吧...
[解决办法]
var list_array:Array = new Array();
var list_xml:XML = new XML();
list_xml.ignoreWhite = true;
list_xml.onLoad = function(success:Boolean) {
if (success) {
for (var aNode:XMLNode = list_xml.firstChild.childNodes[0]; aNode != null; aNode=aNode.nextSibling) {
list_array.push(aNode.firstChild.firstChild.nodeValue);
}
loadpic_func();
} else {
trace("加载失败!");
}
};
list_xml.load("pic_list.xml");
///////////////
var pic_mcl:MovieClipLoader = new MovieClipLoader();
this.onLoadInit = function(_mc:MovieClip) {
_mc._width = Stage.width;
_mc._height = Stage.height;
mask_func(_mc);
};
pic_mcl.addListener(this);
var i:Number = 0;
function loadpic_func() {
i++;
i %= list_array.length;
var pic_mc:MovieClip = this.createEmptyMovieClip("pic_mc"+this.getNextHighestDepth(), this.getNextHighestDepth());
pic_mcl.loadClip(list_array[i], pic_mc);
/*
this.pic_mc._x = Stage.width/2;
this.pic_mc._y = Stage.height/2;
this.pic_mc.createEmptyMovieClip("img_mc", 3);


this.pic_mc.img_mc._x = -Stage.width/2;
this.pic_mc.img_mc._y = -Stage.height/2;
*/
}
var mask_num:Number = new Number();
var xmax:Number = Math.ceil(Stage.width/40);
var ymax:Number = Math.ceil(Stage.height/40);
function mask_func(_mc:MovieClip) {
var depth:Number = xmax*ymax;
var mask_mc:MovieClip = this.createEmptyMovieClip("mask_mc"+this.getNextHighestDepth(), this.getNextHighestDepth());
_mc.setMask(mask_mc);
mask_num = Math.floor(Math.random()*6);
for (var x_num:Number = xmax; x_num>=0; x_num--) {
for (var y_num:Number = ymax; y_num>=0; y_num--) {
mask_mc.attachMovie("mask_mc"+mask_num, "mask"+depth, depth+100, {_x:x_num*50-150, _y:y_num*50-100, _xscale:250, _yscale:250});
depth--;
}
}
texiao_func(mask_mc);
}
////////////////////////////////////////////
function texiao_func(_mc:MovieClip) {
var texiao_array:Array = new Array();
var max_num:Number = new Number();
var temp_num:Number = new Number();
var zhu_num:Number = Math.floor(Math.random()*6);
trace(zhu_num);
if (zhu_num == 0) {
for (var x_n:Number = 0; x_n<=ymax; x_n++) {
var xn_array:Array = new Array();
for (var y_n:Number = 0; y_n<=xmax; y_n++) {
xn_array.push(x_n+y_n);
}
texiao_array.push(xn_array);
}
max_num = xmax+ymax+2;
} else if (zhu_num == 1) {
for (var x_n:Number = 0; x_n<=ymax; x_n++) {
var xn_array:Array = new Array();
for (var y_n:Number = 0; y_n<=xmax; y_n++) {
xn_array.push(xmax+ymax-x_n-y_n+1);
}
texiao_array.push(xn_array);
}
max_num = xmax+ymax+2;
} else if (zhu_num == 2) {
for (var x_n:Number = 0; x_n<=ymax; x_n++) {
var xn_array:Array = new Array();
for (var y_n:Number = 0; y_n<=xmax; y_n++) {
xn_array.push(ymax-x_n+y_n);
}
texiao_array.push(xn_array);
}
max_num = xmax+ymax+2;
} else if (zhu_num == 3) {
for (var x_n:Number = 0; x_n<=ymax; x_n++) {
var xn_array:Array = new Array();
for (var y_n:Number = 0; y_n<=xmax; y_n++) {
xn_array.push(xmax+x_n-y_n);
}
texiao_array.push(xn_array);
}
max_num = xmax+ymax+2;
} else if (zhu_num == 4) {
for (var x_n:Number = 0; x_n<=ymax; x_n++) {
var xn_array:Array = new Array();
for (var y_n:Number = 0; y_n<=xmax; y_n++) {
xn_array.push(x_n);
}
texiao_array.push(xn_array);
}
max_num = ymax+2;
} else if (zhu_num == 5) {
for (var x_n:Number = 0; x_n<=ymax; x_n++) {
var xn_array:Array = new Array();
for (var y_n:Number = 0; y_n<=xmax; y_n++) {
xn_array.push(y_n);
}
texiao_array.push(xn_array);
}
max_num = xmax+2;
}
function fan_func() {
for (var x_n:Number = 0; x_n<=ymax; x_n++) {
for (var y_n:Number = 0; y_n<=xmax; y_n++) {
if (texiao_array[x_n][y_n] == temp_num) {
var xu:Number = x_n*xmax+y_n;
_mc["mask"+xu].play();
//trace(xu);
}
}
}
temp_num++;
if (temp_num>max_num) {
clearInterval(id);
}
}
fan_func();
clearInterval(id);
id = setInterval(fan_func, 80);
this["mask_mc"+(_mc.getDepth()-4)].removeMovieClip();
this["pic_mc"+(_mc.getDepth()-5)].removeMovieClip();
setTimeout(function () {
loadpic_func();
}, 3000);
}

网上例子很多

热点排行