Ver Mensaje Individual
  #6 (permalink)  
Antiguo 22/11/2007, 03:25
Avatar de zaida
zaida
 
Fecha de Ingreso: noviembre-2006
Ubicación: Madrid (España)
Mensajes: 266
Antigüedad: 17 años, 5 meses
Puntos: 0
Re: mover fotogramas clave en la linea de tiempo

Código:
//remove a page object
	private._removePage = function (page) {
		if (page == null) return;
		this.handleEvent("onRemovePage", page.page);
		if (page.rearPage != null) this.handleEvent("onRemovePage", page.rearPage, true);
		if (this._flipPages[page.index] != null) {
			this._flipCount	+= page.side;
			delete this._flipPages[page.index];
		}
		delete this._pages[page.index];
		page.removeMovieClip();
	};

	//adjust the page and its mask and shades according to its position
	private._adjustPage = function (page) {
		if (page == null) return;
		var width		= this._pageWidth;
		var height		= this._pageHeight;
		var side		= page.side;
		var pos			= page.position;
		//calculate the mask range
		if (pos == null) {
			var top		= 1;
			var range	= {type:1, a:width, b:width, angle:0, angle2:90, length:height};
			pos			= {x:side * width, y:0};
		} else {
			var top		= pos.top;
			var range	= pos.range != null ? pos.range
						: (pos.range = this._getMaskRange(-side * pos.x, top > 0 ? pos.y : height-pos.y));
			pos.x		= -side * range.x;
			pos.y		= top > 0 ? range.y : height-range.y;
		}
		//adjust page face movie clip
		with (page.face) {
			_x			= pos.x;
			_y			= pos.y;
			_rotation	= side * top * range.angle;
		}
		page.page._y	= top > 0 ? 0 : -height;
		if (page.rearPage != null) page.rearPage._y = top > 0 ? 0 : -height;
		//adjust shade movie clip
		var ratio		= page.shadeRatio = range.type==0
						? (range.a/width < range.b/height ? range.a/width/2 : range.b/height/2)
						: (range.a/width/2 + range.b/width/2);
		var shade		= page.shade;
		if (shade != null) {
			var shadeSet	= this._shade;
			with (shade) {
				_x			= range.a * -side;
				_y			= 0;
				_rotation	= (range.angle2 - 90) * side * top;
				_xscale		= (ratio * shadeSet.sizeMax + (1-ratio) * shadeSet.sizeMin) / 100 * width * side;
				_yscale		= top * range.length;
				_alpha		= ratio * shadeSet.alphaMax + (1-ratio) * shadeSet.alphaMin;
			}
		}
		//adjust page mask movie clip
		this._drawMask(page.pageMask, range.type, range.a, range.b);
		with (page.pageMask) {
			_x			= pos.x;
			_y			= pos.y;
			_rotation	= side * top * range.angle;
			_yscale		= top * 100;
		}
		//adjust page shadow movie clip
		if (page.shadow != null) {
			if (page.position == null) {
				page.shadow._visible	= false;
			} else {
				var shadowSet	= this._pageShadow;
				with (page.shadow) {
					_visible	= true;
					_x			= (range.a - width) * side;
					_y			= top > 0 ? 0 : height;
					_rotation	= (90 - range.angle2) * side * top;
					_xscale		= (ratio * shadowSet.sizeMax + (1-ratio) * shadowSet.sizeMin) / 100 * width * side;
					_yscale		= top * (range.length > width ? range.length : width);
					_alpha		= ratio * shadowSet.alphaMax + (1-ratio) * shadowSet.alphaMin;
				}
				//adjust shadow mask movie clip
				this._drawMask(page.shadowMask, 13-range.type, range.a, range.b);
				with (page.shadowMask) {
					_y			= top > 0 ? 0 : height;
					_yscale		= top * 100;
				}
			}
		}
		//adjust rear page's mask
		var rearPage	= this._pages[page.index + side];
		if (rearPage != null) {
			this._drawMask(rearPage.pageMask, 3-range.type, range.a, range.b);
			with (rearPage.pageMask) {
				_y			= top > 0 ? 0 : height;
				_yscale		= top * 100;
			}
		}
		//adjust opposite page's shade
		var oppoPage	= this._pages[page.index - side];
		if (oppoPage.shade != null) {
			oppoPage.shadeRatio	= ratio;
			with (oppoPage.shade) {
				_x			= -shade._x;
				_y			= top > 0 ? 0 : height;
				_rotation	= -shade._rotation;
				_xscale		= -shade._xscale;
				_yscale		= shade._yscale;
				_alpha		= shade._alpha;
			}
		}
		this.handleEvent("onAdjustPage", page, range);
	};

	//get the mask range according to the right page's top corner at the specified position
	private._getMaskRange = function (x, y) {
		var width		= this._pageWidth;
		var height		= this._pageHeight;
		//adjust x, y to be in the valid range
		var dTop		= Math.sqrt(x*x + y*y);
		if (dTop > width) {
			x			*= width / dTop;
			y			*= width / dTop;
		}
		var dBottom		= Math.sqrt(x*x + (y-height) * (y-height));
		var diagonal	= Math.sqrt(width*width + height*height);
		if (dBottom > diagonal) {
			x			*= diagonal / dBottom;
			y			= (y-height) * diagonal / dBottom + height;
		}
		//calculate the range
		var w_x					= width - x;
		var range				= {x:x, y:y};
		if (w_x == 0) {
			range.type			= 0;	//corner type, 0:triangle, 1:quadrangle
			range.a				= 0;	//side width of the corner
			range.b				= 0;
			range.angle			= 0;	//page rotation angle
			range.sin			= 0;	//sin, cos of page rotation angle
			range.cos			= 1;
			range.angle2		= 45;	//shade rotation angle
			range.length		= 0;	//length of the boundary
		} else {
			range.a				= (w_x + y*y / w_x) / 2;
			range.angle			= Math.atan2(y, w_x - range.a);
			range.sin			= Math.sin(range.angle);
			range.cos			= Math.cos(range.angle);
			range.angle			*= 180/Math.PI;
			if (w_x*w_x + (y-height)*(y-height) <= height*height) {
				range.type		= 0;
				range.b			= range.a * w_x / y + range.a * 0.005;
				range.angle2	= Math.atan2(range.b, range.a) * 180/Math.PI;
				range.length	= Math.sqrt(range.a*range.a + range.b*range.b);
			} else {
				range.type		= 1;
				range.b			= range.a - height * y / w_x + (range.a + range.b) * 0.005;
				range.angle2	= Math.atan2(height, range.a - range.b) * 180/Math.PI;
				range.length	= Math.sqrt(height*height + (range.a-range.b) * (range.a-range.b));
			}
		}
		return range;
	};
sigue:
__________________
-- Cuando sientas miedo y no tengas un hombro dónde apoyarte, no te hundas en la soledad, pues si lo haces fracasarás --