Difference between revisions of "SWF e-book.as"
(do on mouse move) |
(constrain mouse to radius W) |
||
| Line 16: | Line 16: | ||
createEmptyMovieClip("book",2); | createEmptyMovieClip("book",2); | ||
book.hitArea = bg; | book.hitArea = bg; | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
// Draws page lines and folde line based on mouse position | // Draws page lines and folde line based on mouse position | ||
book.onMouseMove = function() { | book.onMouseMove = function() { | ||
| + | |||
| + | w = (width-margin*2)/2; | ||
| + | h = height-margin*2; | ||
| + | |||
| + | // 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 | // Calculate point Z and dy,dx of line C | ||
| − | dx = width-margin- | + | dx = width-margin-x; |
| − | dy = | + | dy = y-margin; |
| − | Zx = | + | Zx = x+dx/2; |
| − | Zy = | + | Zy = y-dy/2; |
// Calculate line D | // Calculate line D | ||
| Line 50: | Line 56: | ||
moveTo(Px,margin); | moveTo(Px,margin); | ||
| − | lineTo( | + | lineTo(margin+width/2+x,margin+y); |
lineTo(width-margin,Qy); | lineTo(width-margin,Qy); | ||
}; | }; | ||
Revision as of 09:19, 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;
// 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 = width-margin-x; dy = y-margin; Zx = x+dx/2; Zy = y-dy/2;
// Calculate line D Px = Zx-(Zy-margin)*dy/dx; Qy = Zy+(width-margin-Zx)*dx/dy;
clear(); lineStyle(3,0); moveTo(margin,margin); lineTo(Px,margin); lineTo(width-margin,Qy); lineTo(width-margin,height-margin); lineTo(margin,height-margin); lineTo(margin,margin); moveTo(width/2,margin); lineTo(width/2,height-margin);
moveTo(Px,margin); lineTo(margin+width/2+x,margin+y); lineTo(width-margin,Qy);
};



