codice://pageflip version 2.02 (200405031400) // //(for the latest version, always check at http://www.iparigrafika.hu/pageflip) // //this code is written by Macc 2004.05.03 //abel@iparigrafika.hu // //this code is opensource // //free use! //but a small credit would be nice:) //trace(this); //trace(_root); //these values can be changed: ------------------------------------------------------------------------- pw = 210; //page width in pixel ph = 450; //page height in pixel //page data... (export names/tearing flag) pageOrder = new Array("page0","page1","page2","page3","page4","page5", "page6", "page7", "page8", "page9"); pageCanTear = new Array(false, false, false, false, false, false, false, false, false); //pages TEAROFF function! page=0; //first page (normally it is 0 = the page before the cover = blank page) maxpage=8; //last page (back cover, should be even number) hcover = true; //hard cover on/off clickarea = 64; //pixel width of the click sensitive area at the edges.. afa = 56; //width of the autoflip starter square. gs = 2; //goto page flip speed ps = 5; //mouse pursuit speed es = 3; //flip speed after mouse btn release canflip = true; //page flipping enabled //do not change these values: --------------------------------------------------------------------------------------------------------------------- _global.mcnt = 0; //counter (used on a page where is an animation) gpage = 0; //gotoPage No gflip = false; //gotoPage flip gdir = 0; //goto direction... aflip = false; //auto flip flip = false; //pageflip flipOff = false; //terminateflip flipOK = false; //good flip hflip = false; //hardflip (the cover of the book) rotz = -30; //hardflip max y difference preflip = false; //corner flip status ctear = false; //actual page status tear = false; teard = 0; tlimit = 80; removedPages = new Array(); //list of removed pages! mpx = 0, mpy = 0; //mousepos at click sx = sy = 0; //startpoint when flipping x = 0; //mouse x,y y = 0; ax = 0; //auto x,y ay = 0; acnt = 0; aadd = 0; aamp = 0; AM = Math.PI/180; stop(); _quality = "BEST"; Stage.scaleMode = "noScale"; function reset() { //initializing pages... --------------------------------------------------------------------------------------- pages.p0.page._x = -pw; pages.p0._x = 0; pages.p1.page._x = -pw; pages.p1._x = 0; pages.flip.p2.page._x = -pw; pages.flip.p2._x = pw; pages.flip.p3.page._x = -pw; pages.flip.p3._x = 0; pages.p4.page._x = -pw; pages.p4._x = pw; pages.p5.page._x = -pw; pages.p5._x = pw; pages.pgrad._visible = pages.mask._visible = pages.flip._visible = false; pages.flip.p3mask._width = pages.pgmask._width = pw*2; pages.center._height = pages.flip.p3mask._height = pages.pgmask._height = ph; pages.flip.fmask.page.pf._width = pw; pages.center._width = 6; pages.flip.fmask.page.pf._height = ph; pageNumber = new Array(); for(i=0;i<=(maxPage+1);i++) pageNumber[i] = i; } mousecontroll = new Object(); //initializing mouse click handler --------------------------------------------------------------------------- mousecontroll.onMouseDown = function() { if(flip && !aflip) {// && !preflip) { flipOK = false; if(sx<0 && pages._xmouse>0) flipOK = true; if(sx>0 && pages._xmouse<0) flipOK = true; flipOff = true; flip = false; } else if((flipoff || aflip || !canflip) && !preflip) { trace("donothing"); } else { var oox = ox; var ooy = oy; var osx = sx; var osy = sy; var hit = hittest(); //hittest if(hit) { anim._visible = false; flip = true; flipOff = false; tear = false; //not tearing yet... ox = sx = hit*pw; if(preflip) { aflip = preflip = false; ox = oox, oy = ooy; sx = osx, sy = osy; } pages.flip.setMask(pages.mask); mpx = pages._xmouse, mpy = pages._ymouse; //_quality = "MEDIUM"; //it is the place to degrade image quality while turning pages if the performance is too low. } } } mousecontroll.onMouseUp = function() { if(flip && !tear) { if((Math.abs(pages._xmouse)>(pw-afa) && Math.abs(pages._ymouse)>(ph/2-afa) && Math.abs(pages._xmouse-mpx)<afa) || preflip) { flip = false; preflip = false; autoflip(); } else if(!preflip) { preflip = false; flipOK = false; if(sx<0 && pages._xmouse>0) flipOK = true; if(sx>0 && pages._xmouse<0) flipOK = true; flipOff = true; flip = false; } } } function hittest() { //hittest at mouse clicks, if click is over the book -> determining turning direction ------------------------------------ var x=pages._xmouse; var y=pages._ymouse; var pmh = ph/2; if(y<=pmh && y>=-pmh && x<=pw && x>=-pw) { //ha a megadott intervallumban klikkelunk, akkor lapozhatunk var r = Math.sqrt(x*x+y*y); var a = Math.asin(y/r); var y = Math.tan(a)*pw; if(y>0 && y>ph/2) y = ph/2; if(y<0 && y<-ph/2) y = - ph/2; oy = sy = y; r0 = Math.sqrt((sy+ph/2)*(sy+ph/2)+pw*pw); r1 = Math.sqrt((ph/2-sy)*(ph/2-sy)+pw*pw); pageN = eval("pages.flip.p2.page"); pageO = eval("pages.flip.p3"); offs = -pw; pages.flip.fmask._x = pw; if(x<-(pw-clickarea) && page>0) { //>-----> flip backward pages.flip.p3._x = 0; hflip = checkCover(page,-1); setPages(page-2,page-1,page,page+1); ctear = pageCanTear[page-1]; return -1; } if(x>(pw-clickarea) && page<maxpage) { //<-----< flip forward pages.flip.p3._x = pw; hflip = checkCover(page,1); setPages(page,page+2,page+1,page+3); ctear = pageCanTear[page+2]; return 1; } } else return 0; //wrong click } function checkCover(p,dir) { if(hcover) { if(dir>0) { if(p==(maxpage-2) || p==0) return true; } else { if(p==maxpage || p==2) return true; } } return false; } function corner() { var x = Math.abs(pages._xmouse); var y = Math.abs(pages._ymouse); if(x>(pw-afa) && x<pw && y>(ph/2-afa) && y<(ph/2)) { return true; } return false; } function oef() { _global.mcnt++; //main counter incrase (need for some page effect); if(!flip && corner()) { //corner mouseover preflip = true; if(!autoflip()) preflip = false; } if(preflip && !corner()) { preflip = false; flip = false; flipOK = false; flipoff = true; } getm(); if(aflip && !preflip) { y = (ay += (sy-ay)/(gflip? gs: ps )); acnt += aadd; ax -= aadd; if(Math.abs(acnt)>pw) { flipOK = true; flipOff = true; flip = false; aflip = false; } } if(flip) { //page turning is in progress... if(tear) { x = tox; y = (toy += teard); teard *= 1.2; if(Math.abs(teard)>1200) { flipOff = true; flip = false; } } else { x = (ox += (x-ox)/(gflip? gs: ps )); y = (oy += (y-oy)/(gflip? gs: ps )); } calc(x,y); //positioning pages and shadows } if(flipOff) { //terminating page turning effect... (comlplete turning... dropped on the other side) if(flipOK || tear) { x = (ox += (-sx-ox)/(gflip? gs: es )); y = (oy += (sy-oy)/(gflip? gs: es )); calc(x,y); if(x/-sx > 0.99 || tear) { //we are done with turning, so stop all turning issue... flip = false; flipOK = flipOff = false; pages.pgrad._visible = pages.flip._visible = false; //_quality = "BEST"; //if quality is decrased during turning effect, you must reset its default value! if(tear) { //if tear: remove page!!! removePage((sx<0)? page: page+1); //removePage(page); page += (sx<0)? -2: 0; } else { page += (sx<0)? -2: 2; //and tourning pages at pagenumber level... } setPages(page,0,0,page+1); tear = false; if(gpage>0) { //gotoflip active -> is there another flipping left? gpage--; autoflip(); } else gflip = false; } } else { //terminating page turning effect... (incomlplete turning... dropped on the dragged side) x = (ox += (sx-ox)/3); y = (oy += (sy-oy)/3); calc(x,y); if(x/sx > 0.99) { //we are done with turning, so stop all turning issue... flip = false; flipOff = false; aflip = false; pages.pgrad._visible = pages.flip._visible = false; //_quality = "HIGH"; //if quality is decrased during turning effect, you must reset its default value! setPages(page,0,0,page+1); //no change at pagenumbers.. } } } }

Rispondi quotando