Difference between revisions of "E-book comb.as"

From Organic Design wiki
m
m ({{as}})
 
(98 intermediate revisions by 2 users not shown)
Line 1: Line 1:
// Code for [[[[SWF e-book]]]] is licensed under [[[[http://www.gnu.org/copyleft/lesser.html|LGPL]]]]
+
// Compile and run in [[[[E-book_comb]]]]{{as}}
 
margin = 50;
 
margin = 50;
 +
i = 0;
 +
speed = 12;
 +
w = (Stage.width-margin*2)/2;
 +
h = Stage.height-margin*2;
  
// This initialises the book page lines
+
//main clip
createEmptyMovieClip("book",1);
+
this.createEmptyMovieClip("book",19);
  
createEmptyMovieClip("right_next",2);
+
//this.createEmptyMovieClip("right_next",17);
 +
this.createEmptyMovieClip("pg1",3);
  
right_next.createTextField('content',0,0,0,50,50);
+
this.createEmptyMovieClip("maskee",8);
with (right_next.content) {
+
this.createEmptyMovieClip("masker",9);
autosize = 'left';
+
this.createEmptyMovieClip("tasker",6);
selectable = false;
+
this.createEmptyMovieClip("taskee",7);
_quality = 'BEST';
+
pg1.loadMovie("/wiki/images/5/5a/Aqua.jpg");
border = false;
+
//this.createEmptyMovieClip("pg2",4);
multiline = true;
 
wordWrap = false;
 
html = true;
 
embedFonts = true;
 
htmlText = '<font color="#ff0000">Hello right world!</font>';
 
}
 
  
createEmptyMovieClip("left_next",3);
 
  
left_next.createTextField('content',0,0,0,50,50);
+
//create following page
with (left_next.content) {
+
masker.createEmptyMovieClip("RightFill",12);
autosize = 'left';
+
tasker.createEmptyMovieClip("MidFill", 13);
selectable = false;
+
/*right_next.createTextField('content',0,0,0,100,50);
_quality = 'BEST';
+
with (right_next.content) {
border = false;
+
autosize = 'left';
multiline = true;
+
selectable = false;
wordWrap = false;
+
_quality = 'BEST';
html = true;
+
border = false;
embedFonts = true;
+
multiline = true;
htmlText = '<font color="#ff0000">Hello left world!</font>';
+
wordWrap = false;
}
+
html = true;
 +
_visible = false;
 +
//  embedFonts = true;
 +
htmlText = '<font color="#ff0000">Hello right world!</font>';
 +
}*/
 +
book.animate = function(i,Tx,Ty){
  
// Draws page lines and fold line based on mouse position
+
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);
 +
};
  
function pageMove() {
+
// main function
 
+
book.pageTurn = function(x,y,ox,oy,Tx,Ty) {
w = (width-margin*2)/2;
+
//calculate fold
h = height-margin*2;
+
a = Math.atan2(y,x);
ox = margin+w;
+
r = Math.sqrt(x*x+y*y);
oy = margin;
+
if (r>w) r=w;
 
+
x = Math.cos(a)*r;
        // Set mouse co-ords
+
y = Math.sin(a)*r;
   
+
// Calculate point Z and dy,dx of line C
  //      if (_xmouse <= 500)
+
dx = w-x;
x = ox-_xmouse;
+
dy = y;
  //    else if (_xmouse >= 400) x = _xmouse-ox;
+
Zx = x+dx/2;
//        else x = _xmouse;
+
Zy = y-dy/2;
 
+
// Calculate line D
  //      if (_ymouse <= 250) y = _ymouse-oy;
+
Px = Zx-Zy*dy/dx;
    //    else if (_ymouse >= 300)  
+
Py = 0;
y = oy-_ymouse;
+
Qx = w;
    //     else y = height/2;
+
 
+
if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; }
// constrain mouse to radius W
+
else {
a = Math.atan2(y,x);
+
Qy = Zy+(w-Zx)*dx/dy;
r = Math.sqrt(x*x+y*y);
+
if (Qy>h || Qy<0) {
if (r>w) r=w;
+
a = Math.atan2(Qy-y,Qx-x);
x = Math.cos(a)*r;
+
if (Qy<0) a += Math.PI;
y = Math.sin(a)*r;
+
Qx = x+Math.cos(a)*h;
 
+
Qy = y+Math.sin(a)*h;
// Calculate point Z and dy,dx of line C
+
Rx = Qx+(Qy-h)/(y-Py)*(Px-x);
dx = w-x;
+
Ry = h;
dy = y;
+
}
Zx = x+dx/2;
+
else { Rx = Qx; Ry = Qy; }
Zy = y-dy/2;
+
if (Qy==0) Rx = w-Qx;
 
+
if (Rx<0) return;
// 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; }
+
//draw lines
if (Qy==0) Rx = w-Qx;
+
book.clear();
if (Rx<0) return;
+
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);
 +
                beginFill(0xcccccc,100);
 +
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(1,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();
 
}
 
}
// Draw page
+
 +
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;*/
 +
};
  
        if (_xmouse <= 200 && _ymouse <= 100) {
+
var mclListener = new Object();
  
clear();
+
mclListener.onLoadInit = function(target_mc) {
lineStyle(3,0);
+
    target_mc.setMask(masker.RightFill);
moveTo(ox,oy);
+
};
lineTo(ox,oy+h);
 
moveTo(ox+w,oy);
 
lineTo(ox-Px,oy+Py);
 
lineTo(ox-Rx,oy+Ry);
 
lineTo(ox-Rx,oy+h);
 
lineTo(ox+w,oy+h);
 
lineTo(ox+w,oy);
 
  
// Draw fold
+
var my_mcl = new MovieClipLoader();
beginFill(0xdddddd,100);
+
my_mcl.addListener(mclListener);
moveTo(ox-x,oy+y);
+
my_mcl.loadClip("/wiki/images/1/1b/Purple.jpg", maskee);
lineTo(ox-Px,oy+Py);
 
lineTo(ox-Rx,oy+Ry);
 
lineTo(ox-Qx,oy+Qy);
 
lineTo(ox-x,oy+y);
 
endFill();
 
  
// orient right_next page
 
_root.left_next._x = ox-x;
 
_root.left_next._y = oy+y;
 
_root.left_next._rotation = -a*57.29578;
 
}
 
  
        else if (_xmouse <= 200 && _ymouse >= 300) {
+
var tclListener = new Object();
  
clear();
+
tclListener.onLoadInit = function(marget_mc) {
lineStyle(3,0);
+
    marget_mc.setMask(tasker.MidFill);
moveTo(ox,oy);
+
};
lineTo(ox,oy-h);
 
moveTo(ox+w,oy);
 
lineTo(ox-Px,oy-Py);
 
lineTo(ox-Rx,oy-Ry);
 
lineTo(ox-Rx,oy-h);
 
lineTo(ox+w,oy-h);
 
lineTo(ox+w,oy);
 
  
// Draw fold
 
beginFill(0xdddddd,100);
 
moveTo(ox-x,oy-y);
 
lineTo(ox-Px,oy-Py);
 
lineTo(ox-Rx,oy-Ry);
 
lineTo(ox-Qx,oy-Qy);
 
lineTo(ox-x,oy-y);
 
endFill();
 
  
// orient left_next page
 
_root.left_next._x = ox-x;
 
_root.left_next._y = oy-y;
 
_root.left_next._rotation = -a*57.29578;
 
  
}
+
var ty_mcl = new MovieClipLoader();
 +
ty_mcl.addListener(tclListener);
 +
ty_mcl.loadClip("/wiki/images/0/0e/Green.jpg", taskee);
  
        else if (_xmouse >= 400 && _ymouse <= 100) {
+
//iterate over frames
 +
reduce = function() {
 +
    if (i) book.animate(i-=speed,Tx,Ty);
 +
};
 +
// for multiple parameters in main function
 +
var coords = new Object();
  
clear();
+
var mouseListener = new Object();
lineStyle(3,0);
 
moveTo(ox,oy);
 
lineTo(ox,oy+h);
 
moveTo(ox-w,oy);
 
lineTo(ox+Px,oy+Py);
 
lineTo(ox+Rx,oy+Ry);
 
lineTo(ox+Rx,oy+h);
 
lineTo(ox-w,oy+h);
 
lineTo(ox-w,oy);
 
 
 
// Draw fold
 
beginFill(0xdddddd,100);
 
moveTo(ox+x,oy+y);
 
lineTo(ox+Px,oy+Py);
 
lineTo(ox+Rx,oy+Ry);
 
lineTo(ox+Qx,oy+Qy);
 
lineTo(ox+x,oy+y);
 
endFill();
 
 
 
// orient right_next page
 
_root.right_next._x = ox+x;
 
_root.right_next._y = oy+y;
 
_root.right_next._rotation = a*57.29578;
 
 
 
}
 
 
 
        else if (_xmouse >= 400 && _ymouse >= 300) {
 
  
clear();
+
mouseListener.onMouseMove = function(){
lineStyle(3,0);
+
if (_xmouse >=400) {
moveTo(ox,oy);
+
  Tx = coords.j = 1;
lineTo(ox,oy-h);
+
  }
moveTo(ox-w,oy);
+
if (_xmouse < 400) {
lineTo(ox+Px,oy-Py);
+
  Tx = coords.j = -1;
lineTo(ox+Rx,oy-Ry);
+
  }
lineTo(ox+Rx,oy-h);
+
if (_ymouse <= 300) Ty = coords.k = -1;
lineTo(ox-w,oy-h);
+
if (_ymouse > 300) Ty = coords.k = 1;
lineTo(ox-w,oy);
+
 +
_root.book.animate(0,Tx,Ty);
 +
};
  
// Draw fold
+
mouseListener.onMouseDown = function(){
beginFill(0xdddddd,100);
+
if (_xmouse >=400) {
moveTo(ox+x,oy-y);
+
  Tx = coords.j = 1;
lineTo(ox+Px,oy-Py);
+
  }
lineTo(ox+Rx,oy-Ry);
+
  if (_xmouse < 400) {
lineTo(ox+Qx,oy-Qy);
+
  Tx = coords.j = -1;
lineTo(ox+x,oy-y);
+
  }
endFill();
+
if (_ymouse <= 300) Ty = coords.k = -1;
 
+
if (_ymouse > 300) Ty = coords.k = 1;
// orient right_next page
+
};
_root.right_next._x = ox+x;
 
_root.right_next._y = oy-y;
 
_root.right_next._rotation = a*57.29578;
 
 
 
}
 
}
 
     
 
 
 
var mouseListener = new Object();
 
  
mouseListener.onMouseMove = pageMove();
+
mouseListener.onMouseUp = function(){
 +
i=600;
 +
};
  
 
Mouse.addListener(mouseListener);
 
Mouse.addListener(mouseListener);

Latest revision as of 09:35, 14 March 2009

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

//main clip this.createEmptyMovieClip("book",19);

//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("/wiki/images/5/5a/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);

               beginFill(0xcccccc,100);

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(1,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("/wiki/images/1/1b/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("/wiki/images/0/0e/Green.jpg", taskee);

//iterate over frames reduce = function() {

   if (i) 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);