Difference between revisions of "SWF e-book.as"

From Organic Design wiki
(handle case of Qy > H)
m
Line 1: Line 1:
 
// Code for [[[[SWF e-book]]]]
 
// Code for [[[[SWF e-book]]]]
margin = 20;
+
margin = 50;
 
 
// bg defines the hitArea which raises mouse events
 
// - this is used so that the book symbol doesn't need to have a filled background
 
createEmptyMovieClip("bg",1);
 
bg._visible = false;
 
bg.beginFill(0,100);
 
bg.moveTo(margin,margin);
 
bg.lineTo(width-margin,margin);
 
bg.lineTo(width-margin,height-margin);
 
bg.lineTo(margin,height-margin);
 
bg.lineTo(margin,margin);
 
bg.endFill();
 
  
 
// This initialises the book page lines
 
// This initialises the book page lines
createEmptyMovieClip("book",2);
+
createEmptyMovieClip("book",1);
book.hitArea = bg;
 
  
 
// Draws page lines and folde line based on mouse position
 
// Draws page lines and folde line based on mouse position
Line 54: Line 41:
 
clear();
 
clear();
 
lineStyle(3,0);
 
lineStyle(3,0);
 +
beginFill(0xffffff,100);
 
moveTo(ox-w,oy);
 
moveTo(ox-w,oy);
 
lineTo(ox+Px,oy+Py);
 
lineTo(ox+Px,oy+Py);
Line 60: Line 48:
 
lineTo(ox-w,oy+h);
 
lineTo(ox-w,oy+h);
 
lineTo(ox-w,oy);
 
lineTo(ox-w,oy);
 +
endFill();
 
moveTo(ox,oy);
 
moveTo(ox,oy);
 
lineTo(ox,oy+h);
 
lineTo(ox,oy+h);

Revision as of 03:24, 22 November 2006

// Code for [[SWF e-book]] margin = 50;

// This initialises the book page lines createEmptyMovieClip("book",1);

// Draws page lines and folde line based on mouse position book.onMouseMove = function() {

w = (width-margin*2)/2; h = height-margin*2; ox = margin+w; oy = margin;

// Get mouse coords relative to book middle x = _xmouse-margin-w; y = _ymouse-margin;

// 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 = Rx = w; Qy = Ry = Zy+(w-Zx)*dx/dy;

if (Qy>h) Qx = w-(Qy-h)/dx*dy;

// Draw page clear(); lineStyle(3,0); beginFill(0xffffff,100); moveTo(ox-w,oy); lineTo(ox+Px,oy+Py); lineTo(ox+Qx,oy+Qy); lineTo(ox+w,oy+h); lineTo(ox-w,oy+h); lineTo(ox-w,oy); endFill(); moveTo(ox,oy); lineTo(ox,oy+h);

// Draw fold beginFill(0xdddddd,100); moveTo(ox+x,oy+y); lineTo(ox+Px,oy+Py); lineTo(ox+Qx,oy+Qy); lineTo(ox+x,oy+y); endFill();

};