Difference between revisions of "E-book comb.as"
(bottomLeft) |
((not!) rotating bkgd) |
||
Line 1: | Line 1: | ||
− | + | // Compile and run in [[[[Bookclick]]]] | |
− | + | margin = 50; | |
− | + | i = 0; | |
− | + | speed = 8; | |
− | + | //main clip | |
+ | createEmptyMovieClip("book",1); | ||
− | + | createEmptyMovieClip("right_next",2); | |
− | + | createEmptyMovieClip("pg1",3); | |
− | + | createEmptyMovieClip("pg2",4); | |
− | + | createEmptyMovieClip("pg3",5); | |
− | + | createEmptyMovieClip("pg4",6); | |
+ | //create following 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 = '<font color="#ff0000">Hello right world!</font>'; | ||
+ | } | ||
+ | pg1.loadMovie("1.jpg"); | ||
− | + | // 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; | ||
+ | //mousemove | ||
+ | if (!i) { | ||
+ | x= _xmouse-ox; | ||
+ | y= _ymouse-oy; | ||
+ | x=x*Tx; | ||
+ | if (Ty == 1) { | ||
+ | oy = margin + h; | ||
+ | y= oy-_ymouse; | ||
+ | } | ||
+ | } | ||
+ | //onclick | ||
+ | if (i) { | ||
+ | v = i; | ||
+ | if (Tx == -1) { | ||
+ | v = 609-i; | ||
+ | } | ||
+ | x = (v-ox)*Tx; | ||
+ | y = 50; | ||
+ | if (Ty == 1) { | ||
+ | oy = margin + h; | ||
+ | } | ||
+ | } | ||
+ | //calculate fold | ||
+ | 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; | ||
+ | } | ||
+ | //draw lines | ||
+ | clear(); | ||
+ | lineStyle(3,0); | ||
+ | moveTo(ox,oy); | ||
+ | lineTo(ox,oy-h*Ty); | ||
+ | moveTo(ox-w*Tx,oy); | ||
+ | lineTo(ox+Px*Tx,oy-Py*Ty); | ||
+ | lineTo(ox+Rx*Tx,oy-Ry*Ty); | ||
+ | lineTo(ox+Rx*Tx,oy-h*Ty); | ||
+ | lineTo(ox-w*Tx,oy-h*Ty); | ||
+ | lineTo(ox-w*Tx,oy); | ||
+ | //draw fold | ||
+ | beginFill(0xdddddd,100); | ||
+ | moveTo(ox+x*Tx,oy-y*Ty); | ||
+ | lineTo(ox+Px*Tx,oy-Py*Ty); | ||
+ | lineTo(ox+Rx*Tx,oy-Ry*Ty); | ||
+ | lineTo(ox+Qx*Tx,oy-Qy*Ty); | ||
+ | lineTo(ox+x*Tx,oy-y*Ty); | ||
+ | endFill(); | ||
+ | |||
+ | // orient right_next page | ||
− | if ( | + | _root.right_next._x = ox+x; |
− | + | _root.right_next._y = oy+y; | |
− | + | pg1._x = ox + x; | |
− | + | pg1._y = oy + y; | |
− | + | pg1._rotation = a*57.29578; | |
− | + | } | |
− | + | ||
− | + | //iterate over frames | |
− | + | function reduce() { | |
− | + | if (i) pageTurn(i-=speed,Tx,Ty); | |
− | + | } | |
− | + | // for multiple parameters in main function | |
− | + | var coords = new Object(); | |
− | + | //Tx = coords.j = 0; | |
− | + | //Ty = coords.k = 0; | |
+ | var mouseListener = new Object(); | ||
+ | |||
+ | mouseListener.onMouseMove = function(){ | ||
+ | if (_xmouse >=305) { | ||
+ | coords.j = 1; | ||
+ | } | ||
+ | if (_xmouse < 305) { | ||
+ | coords.j = -1; | ||
+ | } | ||
+ | if (_ymouse <= 200) coords.k = -1; | ||
+ | if (_ymouse > 200) coords.k = 1; | ||
+ | |||
+ | Tx = coords.j; | ||
+ | Ty = coords.k; | ||
+ | pageTurn(0,Tx,Ty); | ||
+ | }; | ||
+ | |||
+ | mouseListener.onMouseDown = function(){ | ||
+ | if (_xmouse >=305) { | ||
+ | coords.j = 1; | ||
+ | } | ||
+ | if (_xmouse < 305) { | ||
+ | coords.j = -1; | ||
+ | } | ||
+ | //if (_ymouse <= 150) coords.bar = -1; | ||
+ | //if (_ymouse > 150 && _ymouse <= 250) coords.bar = 0; | ||
+ | //if (_ymouse > 250) coords.bar = 1; | ||
+ | if (_ymouse <= 200) coords.k = -1; | ||
+ | if (_ymouse > 200) coords.k = 1; | ||
+ | Tx = coords.j; | ||
+ | Ty = coords.k; | ||
+ | }; | ||
+ | |||
+ | mouseListener.onMouseUp = function(){ | ||
+ | i=600; | ||
+ | }; | ||
+ | |||
+ | Mouse.addListener(mouseListener); |
Revision as of 22:38, 2 January 2007
// Compile and run in [[Bookclick]] margin = 50; i = 0; speed = 8; //main clip createEmptyMovieClip("book",1);
createEmptyMovieClip("right_next",2); createEmptyMovieClip("pg1",3); createEmptyMovieClip("pg2",4); createEmptyMovieClip("pg3",5); createEmptyMovieClip("pg4",6); //create following 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!'; } pg1.loadMovie("1.jpg");
// 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; //mousemove if (!i) { x= _xmouse-ox; y= _ymouse-oy; x=x*Tx; if (Ty == 1) { oy = margin + h; y= oy-_ymouse; } } //onclick if (i) { v = i; if (Tx == -1) { v = 609-i; } x = (v-ox)*Tx; y = 50; if (Ty == 1) { oy = margin + h; } } //calculate fold 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; } //draw lines clear(); lineStyle(3,0); moveTo(ox,oy); lineTo(ox,oy-h*Ty); moveTo(ox-w*Tx,oy); lineTo(ox+Px*Tx,oy-Py*Ty); lineTo(ox+Rx*Tx,oy-Ry*Ty); lineTo(ox+Rx*Tx,oy-h*Ty); lineTo(ox-w*Tx,oy-h*Ty); lineTo(ox-w*Tx,oy); //draw fold beginFill(0xdddddd,100); moveTo(ox+x*Tx,oy-y*Ty); lineTo(ox+Px*Tx,oy-Py*Ty); lineTo(ox+Rx*Tx,oy-Ry*Ty); lineTo(ox+Qx*Tx,oy-Qy*Ty); lineTo(ox+x*Tx,oy-y*Ty); endFill();
// orient right_next page
_root.right_next._x = ox+x; _root.right_next._y = oy+y; pg1._x = ox + x; pg1._y = oy + y; pg1._rotation = a*57.29578; }
//iterate over frames function reduce() {
if (i) pageTurn(i-=speed,Tx,Ty);
} // for multiple parameters in main function var coords = new Object(); //Tx = coords.j = 0; //Ty = coords.k = 0; var mouseListener = new Object();
mouseListener.onMouseMove = function(){ if (_xmouse >=305) { coords.j = 1; } if (_xmouse < 305) { coords.j = -1; } if (_ymouse <= 200) coords.k = -1; if (_ymouse > 200) coords.k = 1;
Tx = coords.j; Ty = coords.k; pageTurn(0,Tx,Ty); };
mouseListener.onMouseDown = function(){
if (_xmouse >=305) {
coords.j = 1; }
if (_xmouse < 305) {
coords.j = -1; } //if (_ymouse <= 150) coords.bar = -1; //if (_ymouse > 150 && _ymouse <= 250) coords.bar = 0; //if (_ymouse > 250) coords.bar = 1; if (_ymouse <= 200) coords.k = -1; if (_ymouse > 200) coords.k = 1; Tx = coords.j; Ty = coords.k; };
mouseListener.onMouseUp = function(){
i=600;
};
Mouse.addListener(mouseListener);