E-book comb.as

From Organic Design wiki
Revision as of 00:45, 4 January 2007 by Jack (talk | contribs)

// Compile and run in [[E-book_comb]] margin = 50; i = 0; speed = 8; w = (Stage.width-margin*2)/2; h = Stage.height-margin*2;

//main clip createEmptyMovieClip("book",10);

createEmptyMovieClip("right_next",2); createEmptyMovieClip("pg1",3); //create following page pg1.createEmptyMovieClip("RightFill",1); right_next.createTextField('content',0,0,0,100,50); with (right_next.content) { autosize = 'left'; selectable = false; _quality = 'BEST'; border = false; multiline = true; wordWrap = false; html = true; _visible = false; // embedFonts = true; htmlText = 'Hello right world!'; }

function animate (i,Tx,Ty) {

var animpass = new Object(); ox = animpass.ac = margin+w; oy = animpass.ad = margin; //onmousemove if (!i) { x = animpass.aa = _xmouse-ox; y = animpass.ab = _ymouse-oy; x = x*Tx; if (Ty == 1) { oy = animpass.ad = margin + h; y = animpass.ab = oy-_ymouse; } } //onclick if (i) { v = i; if (Tx == -1) { v = 609-i; } x = animpass.aa = (v-ox)*Tx; y = animpass.ab = 50; if (Ty == 1) { oy = animpass.ad = margin + h; } }

pageTurn(x,y,ox,oy,Tx,Ty); }

// main function function pageTurn(x,y,ox,oy,Tx,Ty) { //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(1,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(0xcccccc,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();

with (pg1.RightFill) { clear(); lineStyle(1,0); beginFill(0xffffff,100); moveTo (ox+w*Tx,oy);; lineTo (ox+Px*Tx,oy); lineTo(ox+Rx*Tx,oy-Ry*Ty); lineTo (ox+w*Tx,oy-h*Ty); lineTo (ox+w*Tx,oy); endFill(); } // orient next page right_next.content._visible = true; _root.right_next._x = ox+x; _root.right_next._y = oy+y; //_root.right_next._rotation = a*57.29578; }

var mclListener = new Object();

mclListener.onLoadInit = function(target_mc) {

   target_mc.setMask(pg1.RightFill);

};

System.security.allowDomain("http://www.jack.co.nz");

var my_mcl = new MovieClipLoader(); my_mcl.addListener(mclListener); my_mcl.loadClip("http://www.jack.co.nz/six.jpg", book);

//iterate over frames function reduce() {

   if (i) animate(i-=speed,Tx,Ty);

} // for multiple parameters in main function var coords = new Object();

var mouseListener = new Object();

mouseListener.onMouseMove = function(){ if (_xmouse >=305) { Tx = coords.j = 1; } if (_xmouse < 305) { Tx = coords.j = -1; } if (_ymouse <= 200) Ty = coords.k = -1; if (_ymouse > 200) Ty = coords.k = 1;

animate(0,Tx,Ty); };

mouseListener.onMouseDown = function(){

	if (_xmouse >=305) {

Tx = coords.j = 1; }

  	if (_xmouse < 305) {

Tx = coords.j = -1; } if (_ymouse <= 200) Ty = coords.k = -1; if (_ymouse > 200) Ty = coords.k = 1; };

mouseListener.onMouseUp = function(){

	i=600;

};

Mouse.addListener(mouseListener);