Difference between revisions of "E-book comb.as"
(Animate function removed from pageturn) |
(Masks largely sorted, tho fold needs aligning and rotating. Animation refinements in order now.) |
||
| Line 2: | Line 2: | ||
margin = 50; | margin = 50; | ||
i = 0; | i = 0; | ||
| − | speed = | + | speed = 12; |
w = (Stage.width-margin*2)/2; | w = (Stage.width-margin*2)/2; | ||
h = Stage.height-margin*2; | h = Stage.height-margin*2; | ||
//main clip | //main clip | ||
| − | createEmptyMovieClip("book", | + | this.createEmptyMovieClip("book",1); |
| + | |||
| + | //this.createEmptyMovieClip("right_next",17); | ||
| + | this.createEmptyMovieClip("pg1",3); | ||
| + | |||
| + | this.createEmptyMovieClip("maskee",8); | ||
| + | this.createEmptyMovieClip("masker",9); | ||
| + | this.createEmptyMovieClip("tasker",6); | ||
| + | this.createEmptyMovieClip("taskee",7); | ||
| + | pg1.loadMovie("aqua.jpg"); | ||
| + | //this.createEmptyMovieClip("pg2",4); | ||
| + | |||
| − | |||
| − | |||
//create following page | //create following page | ||
| − | + | masker.createEmptyMovieClip("RightFill",12); | |
| − | right_next.createTextField('content',0,0,0,100,50); | + | tasker.createEmptyMovieClip("MidFill", 13); |
| + | /*right_next.createTextField('content',0,0,0,100,50); | ||
with (right_next.content) { | with (right_next.content) { | ||
autosize = 'left'; | autosize = 'left'; | ||
| Line 25: | Line 35: | ||
// embedFonts = true; | // embedFonts = true; | ||
htmlText = '<font color="#ff0000">Hello right world!</font>'; | htmlText = '<font color="#ff0000">Hello right world!</font>'; | ||
| − | } | + | }*/ |
| + | book.animate = function(i,Tx,Ty){ | ||
| − | |||
| − | |||
var animpass = new Object(); | var animpass = new Object(); | ||
ox = animpass.ac = margin+w; | ox = animpass.ac = margin+w; | ||
| Line 46: | Line 55: | ||
v = i; | v = i; | ||
if (Tx == -1) { | if (Tx == -1) { | ||
| − | v = | + | v = 800-i; |
} | } | ||
x = animpass.aa = (v-ox)*Tx; | x = animpass.aa = (v-ox)*Tx; | ||
| Line 55: | Line 64: | ||
} | } | ||
| − | pageTurn(x,y,ox,oy,Tx,Ty); | + | book.pageTurn(x,y,ox,oy,Tx,Ty); |
| − | } | + | }; |
// main function | // main function | ||
| − | function | + | book.pageTurn = function(x,y,ox,oy,Tx,Ty) { |
//calculate fold | //calculate fold | ||
a = Math.atan2(y,x); | a = Math.atan2(y,x); | ||
| Line 92: | Line 101: | ||
} | } | ||
//draw lines | //draw lines | ||
| + | book.clear(); | ||
| + | book.lineStyle(1,100); | ||
| + | book.moveTo(ox,oy-h*Ty); | ||
| + | book.lineTo(ox+w*Tx,oy-h*Ty); | ||
| + | book.lineTo(ox+w*Tx,oy); | ||
| + | book.lineTo(ox,oy); | ||
| + | book.moveTo(ox-w*Tx,oy); | ||
| + | book.lineTo(ox+Px*Tx,oy-Py*Ty); | ||
| + | book.lineTo(ox+Rx*Tx,oy-Ry*Ty); | ||
| + | book.lineTo(ox+Rx*Tx,oy-h*Ty); | ||
| + | book.lineTo(ox-w*Tx,oy-h*Ty); | ||
| + | book.lineTo(ox-w*Tx,oy); | ||
| + | book.moveTo(ox+x*Tx,oy-y*Ty); | ||
| + | book.lineTo(ox+Px*Tx,oy-Py*Ty); | ||
| + | book.lineTo(ox+Rx*Tx,oy-Ry*Ty); | ||
| + | book.lineTo(ox+Qx*Tx,oy-Qy*Ty); | ||
| + | book.lineTo(ox+x*Tx,oy-y*Ty); | ||
| + | //book.endFill(); | ||
| + | |||
| + | with (masker.RightFill) { | ||
clear(); | clear(); | ||
| − | lineStyle( | + | lineStyle(3,100); |
| − | + | beginFill(0xffffff,100); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | beginFill( | ||
moveTo(ox+x*Tx,oy-y*Ty); | moveTo(ox+x*Tx,oy-y*Ty); | ||
lineTo(ox+Px*Tx,oy-Py*Ty); | lineTo(ox+Px*Tx,oy-Py*Ty); | ||
| Line 110: | Line 130: | ||
lineTo(ox+x*Tx,oy-y*Ty); | lineTo(ox+x*Tx,oy-y*Ty); | ||
endFill(); | endFill(); | ||
| + | } | ||
| − | + | with (tasker.MidFill) { | |
clear(); | clear(); | ||
| − | lineStyle(1, | + | lineStyle(1,100); |
| − | beginFill(0xffffff,100); | + | beginFill (0xffffff,100); |
| − | moveTo (ox | + | moveTo (ox-w*Tx,oy);; |
lineTo (ox+Px*Tx,oy); | lineTo (ox+Px*Tx,oy); | ||
lineTo(ox+Rx*Tx,oy-Ry*Ty); | lineTo(ox+Rx*Tx,oy-Ry*Ty); | ||
| − | lineTo (ox+w*Tx,oy-h*Ty); | + | lineTo(ox+Rx*Tx,oy-h*Ty); |
| − | lineTo (ox | + | lineTo (ox-w*Tx,oy-h*Ty); |
| + | lineTo (ox-w*Tx,oy); | ||
endFill(); | endFill(); | ||
} | } | ||
// orient next page | // orient next page | ||
| − | + | /* right_next.content._visible = true; | |
| − | _root.right_next._x = ox+ | + | _root.right_next._x = ox+Rx*Tx; |
| − | _root.right_next._y = oy | + | _root.right_next._y = oy-Ry*Ty; |
| − | //_root.right_next._rotation = a*57.29578; | + | //_root.right_next._rotation = a*57.29578;*/ |
| − | } | + | }; |
var mclListener = new Object(); | var mclListener = new Object(); | ||
mclListener.onLoadInit = function(target_mc) { | mclListener.onLoadInit = function(target_mc) { | ||
| − | target_mc.setMask( | + | target_mc.setMask(masker.RightFill); |
}; | }; | ||
| − | |||
| − | |||
var my_mcl = new MovieClipLoader(); | var my_mcl = new MovieClipLoader(); | ||
my_mcl.addListener(mclListener); | my_mcl.addListener(mclListener); | ||
| − | my_mcl.loadClip(" | + | my_mcl.loadClip("purple.jpg", maskee); |
| + | |||
| + | |||
| + | var tclListener = new Object(); | ||
| + | |||
| + | tclListener.onLoadInit = function(marget_mc) { | ||
| + | marget_mc.setMask(tasker.MidFill); | ||
| + | }; | ||
| + | |||
| + | |||
| + | |||
| + | var ty_mcl = new MovieClipLoader(); | ||
| + | ty_mcl.addListener(tclListener); | ||
| + | ty_mcl.loadClip("green.jpg", taskee); | ||
//iterate over frames | //iterate over frames | ||
| − | function | + | book.reduce = function() { |
| − | if (i) animate(i-=speed,Tx,Ty); | + | if (i) _root.book.animate(i-=speed,Tx,Ty); |
| − | } | + | }; |
// for multiple parameters in main function | // for multiple parameters in main function | ||
var coords = new Object(); | var coords = new Object(); | ||
| Line 151: | Line 184: | ||
mouseListener.onMouseMove = function(){ | mouseListener.onMouseMove = function(){ | ||
| − | if (_xmouse >= | + | if (_xmouse >=400) { |
Tx = coords.j = 1; | Tx = coords.j = 1; | ||
} | } | ||
| − | if (_xmouse < | + | if (_xmouse < 400) { |
Tx = coords.j = -1; | Tx = coords.j = -1; | ||
} | } | ||
| − | if (_ymouse <= | + | if (_ymouse <= 300) Ty = coords.k = -1; |
| − | if (_ymouse > | + | if (_ymouse > 300) Ty = coords.k = 1; |
| − | animate(0,Tx,Ty); | + | _root.book.animate(0,Tx,Ty); |
}; | }; | ||
mouseListener.onMouseDown = function(){ | mouseListener.onMouseDown = function(){ | ||
| − | if (_xmouse >= | + | if (_xmouse >=400) { |
Tx = coords.j = 1; | Tx = coords.j = 1; | ||
} | } | ||
| − | if (_xmouse < | + | if (_xmouse < 400) { |
Tx = coords.j = -1; | Tx = coords.j = -1; | ||
} | } | ||
| − | if (_ymouse <= | + | if (_ymouse <= 300) Ty = coords.k = -1; |
| − | if (_ymouse > | + | if (_ymouse > 300) Ty = coords.k = 1; |
}; | }; | ||
Revision as of 23:48, 4 January 2007
// Compile and run in [[E-book_comb]] margin = 50; i = 0; speed = 12; w = (Stage.width-margin*2)/2; h = Stage.height-margin*2;
//main clip this.createEmptyMovieClip("book",1);
//this.createEmptyMovieClip("right_next",17); this.createEmptyMovieClip("pg1",3);
this.createEmptyMovieClip("maskee",8); this.createEmptyMovieClip("masker",9); this.createEmptyMovieClip("tasker",6); this.createEmptyMovieClip("taskee",7); pg1.loadMovie("aqua.jpg"); //this.createEmptyMovieClip("pg2",4);
//create following page
masker.createEmptyMovieClip("RightFill",12);
tasker.createEmptyMovieClip("MidFill", 13);
/*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!';
}*/
book.animate = function(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 = 800-i; } x = animpass.aa = (v-ox)*Tx; y = animpass.ab = 50; if (Ty == 1) { oy = animpass.ad = margin + h; } }
book.pageTurn(x,y,ox,oy,Tx,Ty); };
// main function book.pageTurn = function(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 book.clear(); book.lineStyle(1,100); book.moveTo(ox,oy-h*Ty); book.lineTo(ox+w*Tx,oy-h*Ty); book.lineTo(ox+w*Tx,oy); book.lineTo(ox,oy); book.moveTo(ox-w*Tx,oy); book.lineTo(ox+Px*Tx,oy-Py*Ty); book.lineTo(ox+Rx*Tx,oy-Ry*Ty); book.lineTo(ox+Rx*Tx,oy-h*Ty); book.lineTo(ox-w*Tx,oy-h*Ty); book.lineTo(ox-w*Tx,oy); book.moveTo(ox+x*Tx,oy-y*Ty); book.lineTo(ox+Px*Tx,oy-Py*Ty); book.lineTo(ox+Rx*Tx,oy-Ry*Ty); book.lineTo(ox+Qx*Tx,oy-Qy*Ty); book.lineTo(ox+x*Tx,oy-y*Ty); //book.endFill();
with (masker.RightFill) { clear(); lineStyle(3,100); beginFill(0xffffff,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 (tasker.MidFill) { clear(); lineStyle(1,100); beginFill (0xffffff,100); moveTo (ox-w*Tx,oy);; lineTo (ox+Px*Tx,oy); 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); endFill(); } // orient next page /* right_next.content._visible = true; _root.right_next._x = ox+Rx*Tx; _root.right_next._y = oy-Ry*Ty; //_root.right_next._rotation = a*57.29578;*/ };
var mclListener = new Object();
mclListener.onLoadInit = function(target_mc) {
target_mc.setMask(masker.RightFill);
};
var my_mcl = new MovieClipLoader(); my_mcl.addListener(mclListener); my_mcl.loadClip("purple.jpg", maskee);
var tclListener = new Object();
tclListener.onLoadInit = function(marget_mc) {
marget_mc.setMask(tasker.MidFill);
};
var ty_mcl = new MovieClipLoader(); ty_mcl.addListener(tclListener); ty_mcl.loadClip("green.jpg", taskee);
//iterate over frames book.reduce = function() {
if (i) _root.book.animate(i-=speed,Tx,Ty);
}; // for multiple parameters in main function var coords = new Object();
var mouseListener = new Object();
mouseListener.onMouseMove = function(){ if (_xmouse >=400) { Tx = coords.j = 1; } if (_xmouse < 400) { Tx = coords.j = -1; } if (_ymouse <= 300) Ty = coords.k = -1; if (_ymouse > 300) Ty = coords.k = 1;
_root.book.animate(0,Tx,Ty); };
mouseListener.onMouseDown = function(){
if (_xmouse >=400) {
Tx = coords.j = 1; }
if (_xmouse < 400) {
Tx = coords.j = -1; } if (_ymouse <= 300) Ty = coords.k = -1; if (_ymouse > 300) Ty = coords.k = 1; };
mouseListener.onMouseUp = function(){
i=600;
};
Mouse.addListener(mouseListener);



