Difference between revisions of "SWF e-book.as"
(constrain mouse to radius W) |
(change coords relative to book center) |
||
| Line 22: | Line 22: | ||
w = (width-margin*2)/2; | w = (width-margin*2)/2; | ||
h = height-margin*2; | h = height-margin*2; | ||
| + | ox = margin+w; | ||
| + | oy = margin; | ||
// Get mouse coords relative to book middle | // Get mouse coords relative to book middle | ||
| Line 35: | Line 37: | ||
// Calculate point Z and dy,dx of line C | // Calculate point Z and dy,dx of line C | ||
| − | dx = | + | dx = w-x; |
| − | dy = y | + | dy = y; |
Zx = x+dx/2; | Zx = x+dx/2; | ||
Zy = y-dy/2; | Zy = y-dy/2; | ||
// Calculate line D | // Calculate line D | ||
| − | Px = Zx- | + | Px = Zx-Zy*dy/dx; |
| − | Qy = Zy+( | + | Qy = Zy+(w-Zx)*dx/dy; |
clear(); | clear(); | ||
lineStyle(3,0); | lineStyle(3,0); | ||
| − | moveTo( | + | moveTo(ox-w,oy); |
| − | lineTo(Px, | + | lineTo(ox+Px,oy); |
| − | lineTo( | + | lineTo(ox+w,oy+Qy); |
| − | lineTo( | + | lineTo(ox+w,oy+h); |
| − | lineTo( | + | lineTo(ox-w,oy+h); |
| − | lineTo( | + | lineTo(ox-w,oy); |
| − | moveTo( | + | moveTo(ox,oy); |
| − | lineTo( | + | lineTo(ox,oy+h); |
| − | moveTo(Px, | + | moveTo(ox+Px,oy); |
| − | lineTo( | + | lineTo(ox+x,oy+y); |
| − | lineTo( | + | lineTo(ox+w,oy+Qy); |
}; | }; | ||
Revision as of 09:29, 21 November 2006
margin = 20;
// 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 createEmptyMovieClip("book",2); book.hitArea = bg;
// 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-width/2; 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; Qy = Zy+(w-Zx)*dx/dy;
clear(); lineStyle(3,0); moveTo(ox-w,oy); lineTo(ox+Px,oy); lineTo(ox+w,oy+Qy); lineTo(ox+w,oy+h); lineTo(ox-w,oy+h); lineTo(ox-w,oy); moveTo(ox,oy); lineTo(ox,oy+h);
moveTo(ox+Px,oy); lineTo(ox+x,oy+y); lineTo(ox+w,oy+Qy);
};



