Bookclick.as
// Compile and run in [[Bookclick]] margin = 50; i = 0; speed = 8; //main clip createEmptyMovieClip("book",1);
createEmptyMovieClip("right_next",2); //backing page right_next.createTextField('content',0,0,0,50,50); with (right_next.content) {
autosize = 'left'; selectable = false; _quality = 'BEST'; border = false; multiline = true; wordWrap = false; html = true; embedFonts = true; htmlText = 'Hello right world!'; }
function calculate() { // constrain mouse to radius W a = Math.atan2(y,x); r = Math.sqrt(x*x+y*y); if (r>w) r=w; x = Math.cos(a)*r; y = Math.sin(a)*r; // Calculate point Z and dy,dx of line C dx = w-x; dy = y; Zx = x+dx/2; Zy = y-dy/2; // Calculate line D Px = Zx-Zy*dy/dx; Py = 0; Qx = w;
if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; } else { Qy = Zy+(w-Zx)*dx/dy; if (Qy>h || Qy<0) { a = Math.atan2(Qy-y,Qx-x); if (Qy<0) a += Math.PI; Qx = x+Math.cos(a)*h; Qy = y+Math.sin(a)*h; Rx = Qx+(Qy-h)/(y-Py)*(Px-x); Ry = h; } else { Rx = Qx; Ry = Qy; } if (Qy==0) Rx = w-Qx; if (Rx<0) return; } }
// main function takes three parameters (an iterator and x and y mouse)
function pageTurn(i,Tx,Ty) {
w = (Stage.width-margin*2)/2; h = Stage.height-margin*2; ox = margin+w; oy = margin; //these need to change sign later j = Tx; k = Ty; //mousemove if (!i) { x= _xmouse-ox; y= _ymouse-oy; x=x*j; if (Ty == 1) { oy = margin + h; y= oy-_ymouse; } } //onclick if (i) { if (i > 706) return; if (i < -98) return; x = (i-ox); x = x*j; if (Ty == 0) { y = 0; k = -1; } if (Ty == -1) { y= _ymouse; if (x <= -400) y = 0; } if (Ty == 1) { oy = margin + h; y= oy-_ymouse; if (x <= -400) y = 0; } } //calculate fold calculate(); //adjust draw for mouse position w = w*j; x=x*j; Px=Px*j; Rx=Rx*j; Qx=Qx*j; h= h*k; y = y*k; Py = Py*k; Ry = Ry*k; Qy = Qy*k; //draw lines clear(); lineStyle(3,0); moveTo(ox,oy); lineTo(ox,oy-h); moveTo(ox-w,oy); lineTo(ox+Px,oy-Py); lineTo(ox+Rx,oy-Ry); lineTo(ox+Rx,oy-h); lineTo(ox-w,oy-h); lineTo(ox-w,oy); //draw fold beginFill(0xdddddd,100); moveTo(ox+x,oy-y); lineTo(ox+Px,oy-Py); lineTo(ox+Rx,oy-Ry); lineTo(ox+Qx,oy-Qy); lineTo(ox+x,oy-y); endFill();
} //iterates over frames function reduce() {
if (i) pageTurn(i-=speed,Tx,Ty);
} // for multiple parameters in main function var coords = new Object(); Tx = coords.across = 0; Ty = coords.bar = 0; var mouseListener = new Object();
mouseListener.onMouseMove = function(){ if (_xmouse >=305) { coords.across = 1; } if (_xmouse < 305) { coords.across = -1; } if (_ymouse <= 200) coords.bar = -1; if (_ymouse > 200) coords.bar = 1;
Tx = coords.across; Ty = coords.bar; pageTurn(0,Tx,Ty); };
mouseListener.onMouseUp = function(){
if (_xmouse >=305) {
coords.across = 1; i=559; }
if (_xmouse < 305) {
coords.across = -1; i=50; speed = -speed; } if (_ymouse <= 150) coords.bar = -1; if (_ymouse > 150 && _ymouse <= 250) coords.bar = 0; if (_ymouse > 250) coords.bar = 1;
Tx = coords.across; Ty = coords.bar; };
Mouse.addListener(mouseListener);