图片突出展(一) as2版

stop();

init();

function init() {
	rotateDirection = "left";//默认向左旋转,即浏览右边的图片
	imgSpeed = 8;//图片切换状态所花时间
	rotateSpeed = 1500;//图片循环显示间隔时间3.5秒

	imageWidth = 226;//图片宽度
	imageHeight = 220;//图片高度

	perWidth = imageWidth / 10;
	perHeight = imageHeight / 10;

	//centerX = Stage.width / 2 - 340 / 2;//舞台中央x坐标342
	//centerY = Stage.height / 2 - 340 / 2;//舞台中央y坐标214
	centerX=Stage.width/2
	centerY=Stage.height/2
	trace("centerX=" + centerX);
	trace("centerY=" + centerY);

	this.createEmptyMovieClip("imgHolder",1);//创建一个装图片的容器,并设置其深度索引为1
	//imgHolder._x = centerX - 450;//-108
	//imgHolder._y = centerY - 240;//-26	
	imgHolder._x=400;
	imgHolder._y=245;
	trace("imgHolder._x =" + imgHolder._x);
	trace("imgHolder._y =" + imgHolder._y);

	//每个位置图片的alpha
	targetAlpha = [20,40, 60, 80, 100, 80, 60, 40,20];
	//每个位置图片的x坐标
	targetX=[-290,-257,-210,-125,0,158,292,388,467];	
	//每个位置图片y坐标
	targetY = [imageHeight*0.4,imageHeight*0.3, imageHeight*0.2, imageHeight*0.1, 0, imageHeight*0.1, imageHeight*0.2, imageHeight*0.3,imageHeight*0.4];
	
	//每个位置图片的缩放比例
	targetScale = [20,40, 60, 80, 100, 80, 60, 40,20];
	//每个位置图片的深度索引值
	imageDepth = [0,80, 90, 110, 200, 112, 100,88, 0];

	leftBtn.swapDepths(3000);
	rightBtn.swapDepths(3001);
	disable_btn.swapDepths(3002);

	textVisible = [false,false, false, false, true, false, false, false, false];

	totalNum = imgNum;
	indexNum = 1;

	disable_btn._visible = false;
	disable_btn._width = Stage.width;
	disable_btn._height = Stage.height;
	disable_btn.onRollOver = function() {
		this.useHandCursor = false;
		leftBtn.gotoAndStop(1);
		rightBtn.gotoAndStop(1);
	}
	
	for (var i = 0; i < totalNum; i++) {
		imgHolder.attachMovie("img","img" + i,i + 10);//从库中取得一个元件并将其附加到影片剪辑中
		var img = imgHolder["img" + i];//相当于as3中的imgHolder.getChildByName(String("img" + i));
		img._alpha = 0;
		
		img.desc_txt.text = img_name[i];
		img.desc_txt._visible = false;//默认设置所有图片文字不显示

		loadThumbs(thumb_image[i],img.thumbs);
	}

	imgHolder.img3.desc_txt._visible = true;//设置第三张图片文字显示,此处的img2是上面attachMovie里定义的实例名"img" + i

	setMovie();//初始化图片位置及状态
}

//------------------------------------------------------------------------------@载入图片
function loadThumbs(linkUrl, movLoader) {
	var imgLoader = new MovieClipLoader();
	var obj = new Object();
	
	obj.onLoadProgress = function(target, bytesLoaded, bytesTotal) {
		pctLoaded = Math.floor(bytesLoaded / bytesTotal * 100);
		target._parent.pBar_mc.gotoAndPlay(2);
		if (!isNaN(pctLoaded)) {
			if (pctLoaded >= 100) {
				target._parent.pBar_mc.gotoAndPlay(2);
				this.gotoAndPlay(2);
			}
		}
	}
	
	obj.onLoadError = function(target_mc, errorCode, httpStatus) {
	}
	
	obj.onLoadInit = function(target) {
		new mx.transitions.Tween(target._parent.pBar_mc, "_alpha", mx.transitions.easing.Strong.easeOut, target._parent.pBar_mc._alpha, 0, 150, false);
		//此处的target是thumbs容器,设置它的尺寸与图片尺寸一样
		target._width = imageWidth;
		target._height = imageHeight;
	}
	imgLoader.addListener(obj);
	imgLoader.loadClip(linkUrl,movLoader);//载入图片
}

//------------------------------------------------------------------------------@初始化图片位置及状态
function setMovie() {
	for (var i = 0; i < totalNum; i++) {
		posNum = (indexNum + i) % totalNum;

		var img = imgHolder["img" + i];
		img._x = targetX[posNum];
		img._y = targetY[posNum];
		img._xscale = targetScale[posNum];
		img._yscale = targetScale[posNum];
		img._alpha = targetAlpha[posNum];
		img.swapDepths(imageDepth[posNum]);
	}
}

//------------------------------------------------------------------------------@图片状态改变
function rotateMovie() {
	for (var i = 0; i < totalNum; i++) {
		posNum = (indexNum + i) % totalNum;
		//trace("indexNum="+indexNum);
		//trace("posNum="+posNum);

		var img = imgHolder["img" + i];
		img.desc_txt._visible = textVisible[posNum];
		img.swapDepths(imageDepth[posNum]);

		var tween = new mx.transitions.Tween(img, "_x", mx.transitions.easing.Back.easeOut, img._x, targetX[posNum], imgSpeed, false);
		new mx.transitions.Tween(img, "_y", mx.transitions.easing.Back.easeOut, img._y, targetY[posNum], imgSpeed, false);
		new mx.transitions.Tween(img, "_xscale", mx.transitions.easing.Back.easeOut, img._xscale, targetScale[posNum], imgSpeed, false);
		new mx.transitions.Tween(img, "_yscale", mx.transitions.easing.Back.easeOut, img._yscale, targetScale[posNum], imgSpeed, false);
		new mx.transitions.Tween(img, "_alpha", mx.transitions.easing.Back.easeOut, img._alpha, targetAlpha[posNum], imgSpeed, false);
		
		img.onRollOver=function(){
			clearInterval(id);
		}
		img.onRollOut=function(){
			id = setInterval(autoRotate, rotateSpeed);
		}

		img.onRelease = function() {			
			trace(img_name[this._name.substr(3)]);
		}
	}
}

//------------------------------------------------------------------------------@自动向左旋转
function autoRotate() {
	leftBtn.gotoAndStop(1);
	rightBtn.gotoAndStop(1);
	
	//注意indexNum默认起始值是1
	indexNum--;
	if (indexNum == 0) {
		indexNum = totalNum;
	}	
	rotateMovie();
}

//------------------------------------------------------------------------------@上、下页按钮单击侦听
rightBtn.onRelease = function() {
	indexNum++;
	if (indexNum == totalNum) {
		indexNum = 0;
	}
	rotateMovie();
}

leftBtn.onRelease = function() {
	indexNum--;
	if (indexNum == 0) {
		indexNum = totalNum;
	}
	rotateMovie();
}

//------------------------------------------------------------------------------@上、下页按钮鼠标移入、出侦听
leftBtn.onRollOver = function() {
	this.gotoAndStop(2);
	clearInterval(id);
}
rightBtn.onRollOver = function() {
	this.gotoAndStop(2);
	clearInterval(id);
}
rightBtn.onRollOut = function() {
	this.gotoAndStop(1);
	rotateDirection = this._name.substr(0, 5).toString();
	id = setInterval(autoRotate, rotateSpeed);
	trace(rotateDirection);
}
leftBtn.onRollOut = function() {
	this.gotoAndStop(1);
	rotateDirection = this._name.substr(0, 4).toString();
	id = setInterval(autoRotate, rotateSpeed);
	trace(rotateDirection);
}

//------------------------------------------------------------------------------@计时器
id = setInterval(autoRotate, rotateSpeed);

原文地址:https://www.cnblogs.com/leon3286/p/1800748.html