日期:2013-8-13 浏览次数:20229次

  先看看效果:
http://public.iecn.net/freebrandy/ShowImage/ShowImagesIII.swf
改进过程
http://public.iecn.net/freebrandy/ShowImage/ShowImages.swf
http://public.iecn.net/freebrandy/ShowImage/ShowImagesII.swf


源文件下载:picchange.rar
AS类代码:

import mx.events.EventDispatcher;
class ShowImages extends MovieClip {

private var myUrl:Array; //存放图片路径的数组
private var myInfo:Array; //存放图片信息的数组
private var showImageBox:MovieClip; //图片显示区域
private var myLoading:MovieClip //加载图片的MC
private var topMC:MovieClip; //顶部MC
private var buttonMC:MovieClip; //底部MC
private var currentTopMC:MovieClip; //记录当前在较高深度的MC
private var allowToPlayImage:Boolean = true;
private var _id:Number; //定时器ID
private var _showtime:Number = 3000; //定时器时长
private var imageID:Number = 0; //自动播放时保存图片ID值
private var myMask:MovieClip; //遮罩MC
private var ImageDepth:Number=100; //放置图片MC的深度
private var firstLoadImage:Boolean = true; //是否第一次载入图片
//private static var loaderTextFormat:TextFormat = new TextFormat("Arial", null, 0x000000, true);

public var addEventListener:Function;
public var removeEventListener:Function;
private var dispatchEvent:Function;
private static var _mixin1 = EventDispatcher.initialize(ShowImages.prototype);

public function ShowImages() {
fscommand("allowscale",false);
fscommand("showmenu",false);
}
private function onLoad():Void {
//定位至原点
_x = _y = 0;

//添加侦听事件
addEventListener("onPhotoListLoad", this);

//导入存放图片的XML文件
myUrl = new Array();
//myInfo = new Array();
var me:Object = this;
var my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.load("PhotoList.xml");
my_xml.onLoad=function(success){
if (success){
//数组值添加
var xmlA:Array = this.firstChild.childNodes;
var xmlALen:Number = xmlA.length;
for (var i = 0; i<xmlALen; i++) {
me.myUrl.push(xmlA[i].attributes.myUrl);
//me.myInfo.push(xmlA[i].attributes.myInfo);
}
//发出事件给自身
me.dispatchEvent({type:"onPhotoListLoad", target:this});
}
}
}

private function onPhotoListLoad():Void {
//先建立放图片的的MC
showImageBox = this.createEmptyMovieClip("showImageBox",ImageDepth);
myLoading = showImageBox.createEmptyMovieClip("myLoading",ImageDepth+20);
topMC = showImageBox.createEmptyMovieClip("topMC", ImageDepth+10);
//topMC._x = 200;
buttonMC = showImageBox.createEmptyMovieClip("buttonMC", ImageDepth);
//导入图片(loadImage是自循环式函数)
loadImage();
}

private function loadImage():Void {
//先取消定时器
clearInterval(_id);
//取得对象自身,方便访问
var thisObject:Object = this;

//循环控制(这里使用变换深度然后设置遮罩的方法)
if ( imageID == myUrl.length ) imageID = 0;
//第一次载入图片时不需要交换深度
if (firstLoadImage){
currentTopMC = topMC;
firstLoadImage = false;
}else{
//先交换深度
topMC.swapDepths(buttonMC);
//再决定谁在上面
if ( topMC.getDepth() > buttonMC.getDepth() ){
currentTopMC = topMC;
}else{
currentTopMC = buttonMC;
}
}

//在上面的MC导入图片,因为遮罩只对处在上面的MC
currentTopMC.loadMovie(myUrl[imageID]);
//trace(topMC.getDepth());

imageID++;

//导入图片
myLoading.onEnterFrame = function() {
var lb:Number = thisOb