22/11/2007, 03:32
|
| | | Fecha de Ingreso: noviembre-2006 Ubicación: Madrid (España)
Mensajes: 266
Antigüedad: 18 años Puntos: 0 | |
Re: mover fotogramas clave en la linea de tiempo
Código:
//set flipped page's aim position, if not given, it will be set to track mouse
public.setAimPos = function (index, aimX, aimY) {
var page = this._flipPages[int(index)];
if (page == null) return false;
var pos = page.position;
pos.trackMouse = aimX == null;
pos.aimX = aimX == null ? this._xmouse : Number(aimX);
pos.aimY = aimX == null ? this._ymouse : Number(aimY);
return true;
};
//onEnterFrame event handler
public.onEnterFrame = function () {
var moveAcc = this._moveAccRatio;
var dragAcc = this._dragAccRatio;
for (var i in this._flipPages) {
var page = this._pages[i];
var pos = page.position;
if (pos.trackMouse == null) {
if (moveAcc == 0) continue;
pos.x += (pos.aimX - pos.x) * moveAcc;
if (pos.range.angle < 0 && pos.x * page.side < 0) {
pos.y += (pos.aimY - pos.y) * moveAcc * 2;
} else {
pos.y += (pos.aimY - pos.y) * moveAcc;
}
this._adjustPagePos(page);
this.handleEvent("onMovePage", page, pos.x, pos.y);
var dx = pos.aimX - pos.x;
var dy = pos.aimY - pos.y;
if (Math.sqrt(dx*dx + dy*dy) <= Math.abs(this.posPrecision)) this.stopFlip(i, true);
} else {
if (dragAcc == 0) continue;
pos.x += (pos.aimX - pos.x) * dragAcc;
pos.y += (pos.aimY - pos.y) * dragAcc;
this._adjustPagePos(page);
this.handleEvent("onDragPage", page, pos.x, pos.y, pos.trackMouse);
}
}
};
//goto the specified page
public.gotoPage = function (index, rebuildPages) {
if (index == null || isNaN(index)) return false;
index = Math.floor(int(index)/2) * 2;
if (index < Math.floor(this._firstPage/2) * 2) index = Math.floor(this._firstPage/2) * 2;
if (index > Math.floor(this._lastPage/2) * 2) index = Math.floor(this._lastPage/2) * 2;
if (this._pretreating) {
this._curPage = index;
} else if (rebuildPages) {
for (var i in this._pages) this._removePage(this._pages[i]);
var visiblePages = this._visiblePages;
var topDepth = this._topPageDepth;
for (var i = 0, j = index; i < visiblePages; i++, j-=2) this._createPage(j, topDepth - i*2);
for (var i = 0, j = index+1; i < visiblePages; i++, j+=2) this._createPage(j, topDepth - i*2 - 1);
this._curPage = index;
} else {
this.stopFlip(null, true);
var curPage = this._curPage;
this._curPage = index;
if (index == curPage) return true;
var pages = {};
for (var i in this._pages) {
var j = i - curPage + index;
pages[j] = this._pages[i];
pages[j].index = j;
pages[j]._name = "Page" + j;
}
this._pages = pages;
}
return true;
};
//set the index range of the pages
public.setPageRange = function (first, last) {
first = first != null && !isNaN(first) ? (this._firstPage = int(first)) : this._firstPage;
last = last != null && !isNaN(last) ? (this._lastPage = int(last)) : this._lastPage;
if (last < first) {
var t = first;
first = this._firstPage = last;
last = this._lastPage = t;
}
this.gotoPage(this._curPage, true);
};
//GETTER/SETTER PROPERTIES
//the width of the page
gsProperty("pageWidth", function () { return this._pageWidth },
function (value) { this.resizePage(value) }
);
//the height of the page
gsProperty("pageHeight", function () { return this._pageHeight },
function (value) { this.resizePage(null, value) }
);
//the linkage id of the page content movie clip
gsProperty("pageId", function () { return this._pageId },
function (value) {
if (typeof(value) != "string") value = "";
if (this._pageId == value) return;
this._pageId = value;
for (var i in this._pages) this._createPageMC(this._pages[i]);
}
);
//if adjust even page's content position
gsProperty("adjustEvenPage", function () { return this._adjustEvenPage },
function (value) {
var adjustEven = this._adjustEvenPage = value ? true : false;
var width = this._pageWidth;
for (var i in this._pages) {
var page = this._pages[i];
page.page._x = !adjustEven ? width * -page.side : page.side<0 ? 0 : -width;
if (page.rearPage != null) page.rearPage._x = !adjustEven ? page.page._x : page.side<0 ? width : 0;
}
}
);
//automatically go to the definite frame when the page movie clip is created
gsProperty("autoPage", function () { return this._autoPage },
function (value) {
if (this._autoPage = value ? true : false) {
for (var i in this._pages) {
var page = this._pages[i];
page.page.gotoAndStop(page.index - this._firstPage + 1);
page.rearPage.gotoAndStop(page.rearPage.index - this._firstPage + 1);
}
}
}
);
//first page's index
gsProperty("firstPage", function () { return this._firstPage },
function (value) { this.setPageRange(value) }
);
//last page's index
gsProperty("lastPage", function () { return this._lastPage },
function (value) { this.setPageRange(null, value) }
);
//index of the current page
gsProperty("curPage", function () { return this._curPage }, public.gotoPage);
//max count of the visible pages on one side
gsProperty("visiblePages", function () { return this._visiblePages },
function (value) {
var visiblePages = this._visiblePages;
this._visiblePages = value = value > 1 ? int(value) : 1;
if (this._pretreating || visiblePages == value) return;
var flipped = this._flipCount;
if (visiblePages > value) {
var index1 = this._curPage - value*2 + (flipped < 0 ? flipped*2 : 0);
var index2 = this._curPage+1 + value*2 + (flipped > 0 ? flipped*2 : 0);
for (var i = value; i < visiblePages; i++, index1 -= 2, index2 += 2) {
this._removePage(this._pages[index1]);
this._removePage(this._pages[index2]);
}
} else {
var index1 = this._curPage - visiblePages*2 + (flipped < 0 ? flipped*2 : 0);
var index2 = this._curPage+1 + visiblePages*2 + (flipped > 0 ? flipped*2 : 0);
for (var i = visiblePages; i < value; i++, index1 -= 2, index2 += 2) {
this._createPage(index1, this._topPageDepth + (index1 - this._curPage));
this._createPage(index2, this._topPageDepth - (index2 - this._curPage));
}
}
}
);
sigue:
__________________ -- Cuando sientas miedo y no tengas un hombro dónde apoyarte, no te hundas en la soledad, pues si lo haces fracasarás -- |