Difference between revisions of "Bookclick.as"

From Organic Design wiki
m
({{as}})
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
// Code for SWF e-book is liscenced under LGPL
+
// Compile and run in [[[[E-book_comb]]]]{{as}}
margin = Stage.height/8;
+
margin = 50;
 +
i = 0;
 +
speed = 12;
 
w = (Stage.width-margin*2)/2;
 
w = (Stage.width-margin*2)/2;
 
h = Stage.height-margin*2;
 
h = Stage.height-margin*2;
ox = margin+w;
+
gf = 4;
oy = margin;
+
gh = 1;
i = 0;
+
 
speed = 4;
+
//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 initialises the book page lines
+
//create following page
createEmptyMovieClip("book",1);
+
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 = '<font color="#ff0000">Hello right world!</font>';
 +
}*/
 +
 +
book.animate = function(i,Tx,Ty){
  
createEmptyMovieClip("right_next",2);
+
var animpass = new Object();
 +
ox = animpass.ac = margin+w;
 +
oy = animpass.ad = margin;
  
right_next.createTextField('content',0,0,0,50,50);
+
//onmousemove
with (right_next.content) {
+
if (!i) {
    autosize = 'left';
+
x = animpass.aa = _xmouse-ox;
    selectable = false;
+
y = animpass.ab = _ymouse-oy;
    _quality = 'BEST';
+
x = x*Tx;
    border = false;
+
if (Ty == 1) {
    multiline = true;
+
oy = animpass.ad = margin + h;
    wordWrap = false;
+
y = animpass.ab = oy-_ymouse;
    html = true;
+
}
    embedFonts = true;
+
}
    htmlText = '<font color="#ff0000">Hello right world!</font>';
+
//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;
 +
}
 +
}
  
// Draws page lines and fold line based on mouse position
+
book.pageTurn(x,y,ox,oy,Tx,Ty);
 +
};
  
function topRight(i) {
+
// main function
    x= _xmouse-ox;
+
book.pageTurn = function(x,y,ox,oy,Tx,Ty) {
    y= _ymouse-oy;
+
//calculate fold
    if (i) {
+
a = Math.atan2(y,x);
        x = i-ox;
+
r = Math.sqrt(x*x+y*y);
if (y <-5) y = -5;
+
if (r>w) r=w;
        if (x <= -oy*8) y = 0;
+
x = Math.cos(a)*r;
if (y >margin) y = margin;
+
y = Math.sin(a)*r;
    }
+
// Calculate point Z and dy,dx of line C
 
+
dx = w-x;
    // constrain mouse to radius W
+
dy = y;
    a = Math.atan2(y,x);
+
Zx = x+dx/2;
    r = Math.sqrt(x*x+y*y);
+
Zy = y-dy/2;
    if (r>w) r=w;
+
// Calculate line D
    x = Math.cos(a)*r;
+
Px = Zx-Zy*dy/dx;
    y = Math.sin(a)*r;
+
Py = 0;
 +
Qx = w;
 +
 +
if (dy*dy<1) { a = 0; Qx = x>w ? w : x; Qy = Ry = h; Rx = (Qx+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(1,100);
 +
moveTo(ox,oy-h*Ty);
 +
lineTo(ox+w*Tx,oy-h*Ty);
 +
lineTo(ox+w*Tx,oy);
 +
lineTo(ox,oy);
 +
moveTo(ox-w*Tx,oy);
 +
lineTo(ox+Px*Tx,oy-Py*Ty);
 +
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);
 +
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);
 +
moveTo(ox,oy-h*Ty);
 +
lineTo(ox+w*Tx,oy-h*Ty);
 +
lineTo(ox+w*Tx,oy);
 +
lineTo(ox,oy);
 +
moveTo(ox-w*Tx,oy);
 +
lineTo(ox+Px*Tx,oy-Py*Ty);
 +
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);
 +
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;*/
 +
};
  
    // Calculate point Z and dy,dx of line C
+
var mclListener = new Object();
    dx = w-x;
 
    dy = y;
 
    Zx = x+dx/2;
 
    Zy = y-dy/2;
 
  
    // Calculate line D
+
mclListener.onLoadInit = function(target_mc) {
    Px = Zx-Zy*dy/dx;
+
     target_mc.setMask(masker.RightFill);
     Py = 0;
+
};
    Qx = w;
 
  
    if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; }
+
var my_mcl = new MovieClipLoader();
    else {
+
my_mcl.addListener(mclListener);
        Qy = Zy+(w-Zx)*dx/dy;
+
my_mcl.loadClip("purple.jpg", maskee);
        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 page
+
var tclListener = new Object();
    clear();
 
    lineStyle(1,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
+
tclListener.onLoadInit = function(marget_mc) {
    beginFill(0xeeeeee,100);
+
     marget_mc.setMask(tasker.MidFill);
    moveTo(ox+x,oy+y);
+
};
     lineTo(ox+Px,oy);
 
    lineTo(ox+Rx,oy+Ry);
 
    lineTo(ox+Qx,oy+Qy);
 
    lineTo(ox+x,oy+y);
 
    endFill();
 
  
    // orient right_next page
+
var ty_mcl = new MovieClipLoader();
     _root.right_next._x = x;
+
ty_mcl.addListener(tclListener);
    _root.right_next._y = y;
+
ty_mcl.loadClip("green.jpg", taskee);
    _root.right_next._rotation = a*57.29578;
+
 
}
+
//iterate over frames
 
+
book.reduce = function() {
function reduce() {
+
     if (i) _root.book.animate(i-=speed,Tx,Ty);
    if (i) topRight (i-=speed);
+
};
    }
+
// for multiple parameters in main function
 +
var coords = new Object();
 +
 
 +
zoom = function() {
 +
pg1._xscale = 150;
 +
pg1._yscale=150;
 +
book._visible= false;
 +
taskee._visible= false;
 +
tasker._visible= false;
 +
maskee._visible= false;
 +
masker._visible= false;
 +
createEmptyMovieClip("zoommask",14);
 +
zoommask.loadMovie("zoom.gif");
 +
Mouse.hide();
 +
zoommask.startDrag();
 +
zoommask._x = _xmouse;
 +
zoommask._y = _ymouse;
 +
glass = true;
 +
i = 0;
 +
};
  
 
var mouseListener = new Object();
 
var mouseListener = new Object();
 +
 +
mouseListener.onMouseMove = function(){
 +
//trace(_xmouse);
 +
//trace(_ymouse);
 +
if (glass == true) {
 +
createEmptyMovieClip("zoommask",14);
 +
zoommask.loadMovie("zoom.gif");
 +
Mouse.hide();
 +
zoommask.startDrag();
 +
zoommask._x = _xmouse;
 +
zoommask._y = _ymouse;
 +
}
 +
 +
zoommask._visible = false;
 +
 +
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;
 +
if (Tx==-1) gn=gf;
 +
if (Tx==1) gn=gh;
  
mouseListener.onMouseMove = function(){
+
 
     book.onMouseMove = topRight();
+
_root.book.animate(0,Tx,Ty);
 +
};
 +
 
 +
mouseListener.onMouseDown = function(){
 +
if (_xmouse >= 600 ) {
 +
  Tx = coords.j = 1;
 +
  }
 +
if (_xmouse < 600 && _xmouse >= 400) {
 +
  Tx = coords.j = 1;
 +
  }
 +
  if (_xmouse >= 200 && _xmouse < 400) {
 +
  Tx = coords.j = -1;
 +
  }
 +
     if (_xmouse < 200) {
 +
  Tx = coords.j = -1;
 +
  } 
 +
if (_ymouse <= 300) Ty = coords.k = -1;
 +
if (_ymouse > 300) Ty = coords.k = 1;
 
};
 
};
 +
 
mouseListener.onMouseUp = function(){
 
mouseListener.onMouseUp = function(){
    i=Stage.width-margin;
+
 +
gv = gn+".jpg";
 +
pg1.loadMovie(gv);
 +
if (_xmouse>275 && _xmouse<=400) {
 +
if ((_ymouse<50) || (_ymouse>550 && _ymouse<=600)) {
 +
zoom();
 +
}
 +
}
 +
 +
if (_xmouse>400 && _xmouse<=525) {
 +
if ((_ymouse<50) || (_ymouse>550 && _ymouse<=600)) {
 +
zoom();
 +
}
 +
}
  
 +
if (_xmouse<=275 || _xmouse>525){
 +
  zoommask.stopDrag();
 +
Mouse.show();
 +
pg1._xscale = 100;
 +
pg1._yscale=100;
 +
zoommask._visible = false;
 +
book._visible= true;
 +
taskee._visible= true;
 +
tasker._visible= true;
 +
maskee._visible= true;
 +
masker._visible= true;
 +
glass = false;
 +
  i=612;
 +
}
 +
gn = gn + (1*Tx);
 
};
 
};
  
 
Mouse.addListener(mouseListener);
 
Mouse.addListener(mouseListener);

Latest revision as of 09:49, 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; gf = 4; gh = 1;

//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");

//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>w ? w : x; Qy = Ry = h; Rx = (Qx+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(1,100); moveTo(ox,oy-h*Ty); lineTo(ox+w*Tx,oy-h*Ty); lineTo(ox+w*Tx,oy); lineTo(ox,oy); moveTo(ox-w*Tx,oy); lineTo(ox+Px*Tx,oy-Py*Ty); 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); 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); moveTo(ox,oy-h*Ty); lineTo(ox+w*Tx,oy-h*Ty); lineTo(ox+w*Tx,oy); lineTo(ox,oy); moveTo(ox-w*Tx,oy); lineTo(ox+Px*Tx,oy-Py*Ty); 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); 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();

zoom = function() { pg1._xscale = 150; pg1._yscale=150; book._visible= false; taskee._visible= false; tasker._visible= false; maskee._visible= false; masker._visible= false; createEmptyMovieClip("zoommask",14); zoommask.loadMovie("zoom.gif"); Mouse.hide(); zoommask.startDrag(); zoommask._x = _xmouse; zoommask._y = _ymouse; glass = true; i = 0; };

var mouseListener = new Object();

mouseListener.onMouseMove = function(){ //trace(_xmouse); //trace(_ymouse); if (glass == true) { createEmptyMovieClip("zoommask",14); zoommask.loadMovie("zoom.gif"); Mouse.hide(); zoommask.startDrag(); zoommask._x = _xmouse; zoommask._y = _ymouse; }

zoommask._visible = false;

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; if (Tx==-1) gn=gf; if (Tx==1) gn=gh;


_root.book.animate(0,Tx,Ty); };

mouseListener.onMouseDown = function(){

	if (_xmouse >= 600 ) {

Tx = coords.j = 1; } if (_xmouse < 600 && _xmouse >= 400) { Tx = coords.j = 1; }

  	if (_xmouse >= 200 && _xmouse < 400) {

Tx = coords.j = -1; }

   if (_xmouse < 200) {

Tx = coords.j = -1; } if (_ymouse <= 300) Ty = coords.k = -1; if (_ymouse > 300) Ty = coords.k = 1; };

mouseListener.onMouseUp = function(){

gv = gn+".jpg"; pg1.loadMovie(gv); if (_xmouse>275 && _xmouse<=400) { if ((_ymouse<50) || (_ymouse>550 && _ymouse<=600)) { zoom(); } }

if (_xmouse>400 && _xmouse<=525) { if ((_ymouse<50) || (_ymouse>550 && _ymouse<=600)) { zoom(); } }

if (_xmouse<=275 || _xmouse>525){ zoommask.stopDrag(); Mouse.show(); pg1._xscale = 100; pg1._yscale=100; zoommask._visible = false; book._visible= true; taskee._visible= true; tasker._visible= true; maskee._visible= true; masker._visible= true; glass = false; i=612; }

		gn = gn + (1*Tx);

};

Mouse.addListener(mouseListener);