Tuesday, April 19, 2011

Version 4

Finally, I had complete with the advance version of the Interactive E-Menu, have a peek. This version allowed to click to fast link to the page desired, without flipping.




See how it look when click on the dishes.
To order click on the order button, select the amount of dishes.
After done with the selection will appear ' You order is send to kitchen'




Coding

The script that I use

This is the main script for the whole book flipping
//
//
// This file brought to you by: P i X E L W i T . C O M
//
//
//
stop();
//
//
// _________________________V A R I A B L E S
//
// Store a constant reference to this clip on the main timeline so
// clip can be referenced from any other timeline as _level0.pagesAbs
_level0.pagesAbs = this;
// Set page dimensions
var pageWi = 275;
var pageHi = 400;
var pageWiHi = pageWi+pageHi;
var pivotY = pageHi/2+pageWi;
var pageColor = 0xFFFFE5;
// "dir" equals either 1 or -1 and determines if you
// are flipping forward or backward through the book
var dir = 1;
// "flipPage" is the # "between" the two flipping page #'s
var flipPage = 1.5;
// "curPage" is the # between the two currently viewed page #'s
var curPage = .5;
// "maxPages" should be an even number
var maxPages = 12;
// "autoStep" percentage of page width determining step size when auto-closing
var autoStep = .05;
// "dragging" is true if you are dragging the page
var dragging = false;
//
//
//
//
//
// ________________________________R U N O N C E
//
// Place Left and Right page flip Buttons
this.attachMovie("cornerButton", "RButton", 11);
with (RButton) {
_x = pageWi;
_y = -pageWi;
}
this.attachMovie("cornerButton", "LButton", 12);
with (LButton) {
_x = -pageWi;
_y = -pageWi;
_xscale = -100;
}
//
//
// Build pages for first time
pageInit(flipPage, dir);
// Drop down to appear centered
_y += pivotY;
//
//
//
//
//
// _____________________B U I L D F U N C T I O N S
//
// Create a left-aligned page-sized solid fill raised one pagewidth
// If quadrant = 1 page is on the right, if -1 page is on the left
// targ is the clip which hold the page drawing
function makePage(targ, xQuadrant) {
with (targ) {
beginFill(pageColor, 100);
moveTo(0, -pageWi);
lineTo(0, -pageWiHi);
lineTo(xQuadrant*pageWi, -pageWiHi);
lineTo(xQuadrant*pageWi, -pageWi);
endFill();
}
}
//
//
// Create a left-aligned page-sized shadow gradient raised one pagewidth
// Shade is used to add depth to stationary pages
function makeShade(targ, xQuadrant) {
with (targ) {
// Defines gradient used as shadow overlay
var colors = [0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000];
var alphas = [40, 25, 15, 5, 0, 1, 6];
var ratios = [0, 1, 17, 51, 89, 132, 255];
var matrix = {matrixType:"box", x:0, y:pageWi, w:xQuadrant*pageWi, h:pageHi, r:0};
beginGradientFill("linear", colors, alphas, ratios, matrix);
moveTo(0, -pageWi);
lineTo(0, -pageWiHi);
lineTo(xQuadrant*pageWi, -pageWiHi);
lineTo(xQuadrant*pageWi, -pageWi);
endFill();
}
}
//
//
// create a bottom-left aligned shadow gradient
// for animated shadows
function makeShadow(targ, xQuadrant) {
with (targ) {
// Defines gradient used as shadow overlay
var colors = [0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000];
var alphas = [40, 25, 15, 5, 0, 1, 6];
var ratios = [0, 1, 17, 51, 89, 132, 255];
var maxLength = Math.sqrt((pageWi*pageWi)+(pageWiHi*pageWiHi));
var matrix = {matrixType:"box", x:0, y:-maxLength, w:xQuadrant*pageWi, h:maxLength-pageWi, r:0};
beginGradientFill("linear", colors, alphas, ratios, matrix);
moveTo(0, -pageWi);
lineTo(0, -maxLength);
lineTo(xQuadrant*pageWi, -maxLength);
lineTo(xQuadrant*pageWi, -pageWi);
endFill();
}
}
//
//
// Place Stationary Pages
function setStationary() {
// Place the "S"tationary "L"eft "P"age
createEmptyMovieClip("SLPage", 1);
if (flipPage != 1.5) {
makePage(SLPage, -1);
SLPage.attachMovie("print"+(flipPage-1.5), "Print", 1);
with (SLPage.Print) {
_x = -pageWi/2;
_y = -pivotY;
}
}
// Place the "S"tationary "R"ight "P"age
createEmptyMovieClip("SRPage", 2);
if (flipPage != maxPages-.5) {
makePage(SRPage, 1);
SRPage.attachMovie("print"+(flipPage+1.5), "Print", 1);
with (SRPage.Print) {
_x = pageWi/2;
_y = -pivotY;
}
}
// Place shade on page not being revealed
var targ = dir>0 ? SLPage : SRPage;
targ.createEmptyMovieClip("Shade", 2);
makeShade(targ.Shade, -dir);
}
//
//
// Place the Flipping Pages
function setFlipping() {
var targ;
// Place the "F"lipping "T"op "P"age
createEmptyMovieClip("FTPage", 3);
makePage(FTPage, dir);
with (FTPage) {
attachMovie("print"+(flipPage-dir*.5), "Print", 1);
with (Print) {
_x = dir*pageWi/2;
_y = -pivotY;
}
}
FTPage.createEmptyMovieClip("Shade", 2);
makeShade(FTPage.Shade, dir);
// Place the "F"lipping "B"ottom "P"age
createEmptyMovieClip("FBPage", 4);
makePage(FBPage, -dir);
FBPage.attachMovie("print"+(flipPage+dir*.5), "Print", 1);
with (FBPage.Print) {
_x = -dir*pageWi/2;
_y = -pivotY;
}
FBPage._rotation = dir*90;
}
//
//
// Creates Shadows which follow edge of transition
function setShadows() {
var targ;
// Place shadow on the "F"lipping page
this.createEmptyMovieClip("FShadow", 5);
makeShadow(FShadow, -dir);
FShadow._rotation = dir*45;
// Place shadow on the "S"tationary page
this.createEmptyMovieClip("SShadow", 6);
makeShadow(SShadow, dir);
SShadow._rotation = dir*45;
}
//
//
// Create Masks to hide everything
function makeMasks() {
// Create mask for Flipping Bottom Page Mask
this.createEmptyMovieClip("FBPageMask", 7);
with (FBPageMask) {
beginFill(0x005500, 100);
lineTo(pageWiHi, -pageWiHi);
curveTo(0, -2*pageWiHi, -pageWiHi, -pageWiHi);
endFill();
}
// Create mask for Flipping Top Page
FBPageMask.duplicateMovieClip("FTPageMask", 8);
// Create mask for Shadow on the Flipping Page
this.createEmptyMovieClip("FShadowMask", 9);
makePage(FShadowMask, -dir);
FShadowMask._rotation = dir*90;
// Create mask for Shadow on Stationary Page
this.createEmptyMovieClip("SShadowMask", 10);
makePage(SShadowMask, dir);
FBPage.setMask(FBPageMask);
FTPage.setMask(FTPageMask);
FShadow.setMask(FShadowMask);
SShadow.setMask(SShadowMask);
}
//
//
// Hide pages before page1 and after Last Page
function limitBook() {
if (flipPage == 1.5) {
SLPage._visible = 0;
LButton._visible = 0;
SShadow._visible = 0;
if (dir == 1) {
FTPage.Shade._alpha = 67;
SShadow._visible = 1;
} else {
FShadow._alpha = 67;
}
} else if (flipPage == maxPages-.5) {
SRPage._visible = 0;
RButton._visible = 0;
SShadow._visible = 0;
if (dir == -1) {
FTPage.Shade._alpha = 67;
SShadow._visible = 1;
} else {
FShadow._alpha = 67;
}
}
}
//
//
// How to position all pages needed for a page flip
// calls all functions listed above
function pageInit(cp, d) {
flipPage = cp;
dir = d;
// trace ("flip page = "+flipPage+" dir = "+dir);
setStationary();
setFlipping();
setShadows();
makeMasks();
limitBook();
}
//
//
//
//
//
// __________________F L I P P I N G F U N C T I O N S
//
// How to adjust position of flipping page
// based on a value between 0 and 1
function flip(curVal) {
var rot = dir*45*curVal;
FBPageMask._rotation = FTPageMask._rotation=-rot;
FBPage._rotation = FShadowMask._rotation=(dir*90)-rot*2;
FShadow._rotation = SShadow._rotation=(dir*45)-rot;
}
//
//
// how to determine position of flipping page
// returns a value between 0 and 1
// zero being no-flip and one being full-flip
function getPageRatio() {
if (dragging) {
// if dragging page position is determined by mouse position
// the 20 helps advance the turning page when the button is pressed
pageRatio = -dir*(_xmouse-startX-dir*20)/(2*pageWi);
} else {
// if not dragging; auto increment page towards final position
pageRatio>2/3 ? pageRatio += autoStep : pageRatio -= autoStep;
}
// if out of bounds
if (pageRatio<=0) {
pageRatio = 0;
if (!dragging) {
flipDone();
}
} else if (pageRatio>=1) {
pageRatio = 1;
if (!dragging) {
flipDone();
}
}
return (pageRatio);
}
//
//
//
//
//
// _____________C O N T R O L I N G F U N C T I O N S
//
// What to do when you press a page flipping button
function startFlip(dir) {
pageInit(curPage+dir, dir);
startX = dir*pageWi;
dragging = true;
RButton._alpha = 0;
Lbutton._alpha = 0;
this.onEnterFrame = function() {
flip(getPageRatio());
};
}
//
//
// what to do when page is released
function flipRelease() {
dragging = false;
if (pageRatio>2/3) {
curPage += 2*dir;
}
}
function pageJumpL2(){
dir = -1;
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
}

function pageJump2(){
dir = 1;
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
}

function pageJumpL4(){
dir = -1;
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
}

function pageJump4(){
dir = 1;
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
}

function pageJumpL6(){
dir = -1;
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
}

function pageJump6(){
dir = 1;
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
}

function pageJumpL8(){
dir = -1;
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
}

function pageJump8(){
dir = 1;
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
startFlip(dir);
dragging = false;
curPage += 2*dir;
trace("jump "+ pages + " pages");
}
//
//
// What to do when pages are done flipping
function flipDone() {
trace("flip done");
this.onEnterFrame = null;
RButton._alpha = 100;
LButton._alpha = 100;
if (curPage != .5) {
LButton._visible = 1;
}
if (curPage != maxPages+.5) {
RButton._visible = 1;
}
// Delete hidden pages to save resources
if (pageRatio == 0) {
FShadow.removeMovieClip();
FShadowMask.removeMovieClip();
SShadow.removeMovieClip();
SShadowMask.removeMovieClip();
FBPage.removeMovieClip();
FBPageMask.removeMovieClip();
if (dir == 1) {
SRPage.removeMovieClip();
} else {
SLPage.removeMovieClip();
}
} else {
FTPage.removeMovieClip();
if (dir == -1) {
SRPage.removeMovieClip();
} else {
SLPage.removeMovieClip();
}
}
FTPageMask.removeMovieClip();
}
//
//
// assign functions to button events
LButton.onPress = function() {
startFlip(-1);
};
LButton.onReleaseOutside = function() {
flipRelease();
};
LButton.onRelease = function() {
flipRelease();
};
RButton.onPress = function() {
startFlip(1);
};
RButton.onReleaseOutside = function() {
flipRelease();
};
RButton.onRelease = function() {
flipRelease();
};

The loader bar
onClipEvent (load) {
if (_parent.getBytesTotal()<1000) {
fileSize = Math.floor(_parent.getBytesTotal())+"bytes";
} else if (_parent.getBytesTotal()>1000000) {
fileSize = math.floor(_parent.getBytesTotal()/1000000)+"mb";
} else {
fileSize = math.floor(_parent.getBytesTotal()/1000)+"k";
}
message = "";
}
onClipEvent (enterFrame) {
percent = Math.floor(_parent.getBytesLoaded()/_parent.getBytesTotal()*100);
output = percent+"% of "+filesize+" loaded";
Bar._xscale = percent;
if (percent == 100) {
this._visible = 0;
}
}

The script to link to another page
menu.onRelease = function(){ //try go back to prev page
trace("go back")
_root.Pages.pageJumpL2();
}

vege.onRelease = function(){
_root.Pages.pageJump2();
}
seafood.onRelease = function(){
_root.Pages.pageJump2();
}
sidedish.onRelease = function(){
_root.Pages.pageJump4();
}
dessert.onRelease = function(){
_root.Pages.pageJump4();
}
rpn.onRelease = function(){
_root.Pages.pageJump6();
}
tea.onRelease = function(){
_root.Pages.pageJump6();
}

The script to load and unload page
on (release) {
loadMovieNum("p&m1.swf",1);
}
on (release) {
unloadMovieNum(1);
}

Saturday, April 16, 2011

The Device


The device I will be using is View Sonic 10. It able to run swf as it has 2 types of OS, 1 is android, another 1 is window.

Tuesday, April 12, 2011

Version 3

Finally done with the basic part, advancement part coming soon.
This is the interface when select to the dishes, this is only partly shown as it will be too much if shown all.





Friday, April 8, 2011

Version 2

This is the version 2 that I had made, come with design, but my friend say is kinda empty, suggest me that maybe I can 'plant' more flower.

Saturday, April 2, 2011

Reference

Script to play movie clip
on(rollOver, dragOver){
butMC1.gotoAndPlay(2);
_root.canflip=false; // flipping passive
}
on(rollOut, dragOut, releaseOutside){
butMC1.gotoAndPlay(11);
_root.canflip=true; // flipping active
}
on(release){
_root.canflip=true; // flipping active
_root.gotoPage(4,true); // go to page
}

on(release) {
_root.gotoPage(9,true);
}

Script to play URL
on(release){
_root.canflip=true; // flipping active
getURL("javascript:PopUp('PopUpView.html','popup','scrollbars=no','400','230','true')"); // open popup
}

on(release){
var data = _parent.params;
getURL("javascript:MM_openBrWindow('" + data.popup + "','', " + data.w + ", " + data.h + ")", "_self");
}
Script to play video
function onVisible(){
_root.soundsOff(); //stop sounds
videotext.gotoAndStop(1); //text=PLAYED
play();
}
function onInvisible(){
_root.soundsOn(); //start sounds
videotext.gotoAndStop(2); //text=PAUSED
stop();
}

Script for flip book
myBook.onClick = function(pageNumber, page_mc) {
if (page_mc.isLeftPage) {
this.flipBack();
} else {
this.flipForward();
}
};

#initclip
function FFlippingBookConstants() {
this.version = "1.8.6";
this.DELIMITER = "%!!!%";
this.INVALID_XML_MSG = "FFlippingBookError: Incorrect XML source..";
this.MEDIA_INTERVAL = 300;
this.MEDIA_TIMEOUT = 3000;
this.PAGE_TIMEOUT = 3000;
this.DEF_PAGE_NAME = "fpage";
this.PAGE_SHADOW_LAYER_NAME = "shadows";
this.PAGE_BG_NAME = "bg";
this.PAGE_HOLDER_NAME = "holder";
this.PAGE_HOLDER_PARENT_NAME = "parent";
this.PAGE_PRELOADER_NAME = "loader";
this.PAGE_MEDIA_NAME = "media";
this.PAGE_MASK_NAME = "pmask";
this.SYMBOL_PRELOADER_NAME = "FBStandardPreloader";
this.PRELOADER_BAR_NAME = "bar_mc";
this.MAIN_OBJ_ID = "MAIN";
this.MODEL_OBJ_ID = "MODEL";
this.CACHE_OBJ_ID = "CACHE";
this.CONSTANTS_OBJ_ID = "CONSTANTS";
this.LOADER_OBJ_ID = "LOADER";
this.VIEW_OBJ_ID = "VIEW";
this.WIDTH_NODE_NAME = "WIDTH";
this.HEIGHT_NODE_NAME = "HEIGHT";
this.ALWAYS_OPENED_NODE_NAME = "ALWAYSOPENED";
this.SCALE_CONTENT_NODE_NAME = "SCALECONTENT";
this.AUTOFLIP_NODE_NAME = "AUTOFLIP";
this.FLIP_ON_CLICK_NODE_NAME = "FLIPONCLICK";
this.MOVE_SPEED_NODE_NAME = "MOVESPEED";
this.CLOSE_SPEED_NODE_NAME = "CLOSESPEED";
this.GOTO_SPEED_NODE_NAME = "GOTOSPEED";
this.FLIP_SOUND_NODE_NAME = "FLIPSOUND";
this.PAGE_BACK_NODE_NAME = "PAGEBACK";
this.LOAD_ON_DEMAND_NODE_NAME = "LOADONDEMAND";
this.CACHE_PAGES_NODE_NAME = "CACHEPAGES";
this.USE_PRELOADER_NODE_NAME = "USEPRELOADER";
this.USER_PRELOADER_NODE_NAME = "USERPRELOADERID";
this.CACHE_SIZE_NODE_NAME = "CACHESIZE";
this.PRELOADER_TYPE_NODE_NAME = "PRELOADERTYPE";
this.PAGES_NODE_NAME = "PAGES";
this.FIRST_PAGE_NODE_NAME = "FIRSTPAGE";
this.STATIC_SHADOWS_DEPTH_NODE_NAME = "STATICSHADOWSDEPTH";
this.DYNAMIC_SHADOWS_DEPTH_NODE_NAME = "DYNAMICSHADOWSDEPTH";
this.PAGE_STATIC_SHADOW1_NAME = "STATICSH1";
this.PAGE_STATIC_SHADOW2_NAME = "STATICSH2";
this.FLIP_SOUND_SYMBOL_NAME = "FFlippingBookSound";
this.NUM_TYPE_NAME = "number";
this.BOOL_TYPE_NAME = "boolean";
this.BOOL_TRUE_VAL = "TRUE";
this.BOOL_FALSE_VAL = "FALSE";
this.PRELOADER_WIDTH_SCALE = 2;
this.PRELOADER_HEIGHT_SCALE = 30;
this.MIN_PAGE_OFFSET = 0.99;
this.MIN_PAGE_OFFSET2 = 0.99;
this.DEF_PRELOADER_TYPE = "Progress Bar";
this.DEF_CACHE_SIZE = 4;
this.DEF_WIDTH = 100;
this.DEF_HEIGHT = 100;
this.DEF_FIRST_PAGE = 0;
this.DEF_SHADOWS_DEPTH = 1;
this.DEF_MOVE_SPEED = 2;
this.DEF_CLOSE_SPEED = 3;
this.DEF_GOTO_SPEED = 3;
this.DEF_ALWAYS_OPENED = false;
this.DEF_FLIP_ON_CLICK = true;
this.DEF_LOAD_ON_DEMAND = true;
this.DEF_CACHE_PAGES = true;
this.DEF_USE_PRELOADER = true;
this.DEF_PAGEBACK = 0xAEAEAE;
this.DEF_SCALE_CONTENT = true;
this.DEF_SOUND = "default";
this.DEF_NO_SOUND = "";
this.DEF_AUTOFLIP = 50;
this.EMPTY_PAGE = "_empty";
this.TRANSPARENT_PAGE1 = "_transp1";
this.TRANSPARENT_PAGE2 = "_transp2";
this.INIT_STATE = 0;
this.UNACTIVE_STATE = 1;
this.FLIPPING_STATE = 2;
this.FLIPOVER_STATE = 3;
this.FLIPBACK_STATE = 4;
this.AUTOFLIP_STATE = 5;
this.GOTOPAGE_STATE = 6;
this.FLIP_GOTOPAGE_STATE = 7;
this.FLIP_CORNER_STATE = 8;
this.START_FLIP_CORNER_STATE = 9;
this.CACHE_DEPTH = 100;
this.BOOK_DEPTH = 10000;
this.PAGE_01_MC_NAME = "p01";
this.PAGE_02_MC_NAME = "p02";
this.PAGE_03_MC_NAME = "p03";
this.PAGE_04_MC_NAME = "p04";
this.MASK_03_MC_NAME = "m03";
this.MASK_12_MC_NAME = "m12";
this.SHADOW_03_MC_NAME = "s03";
this.SHADOW_04_MC_NAME = "s04";
this.SH_MASK_03_MC_NAME = "shm03";
this.SH_MASK_04_MC_NAME = "shm04";
this.PAGES_SH_MC_NAME = "s12";
this.PAGES_SHM_MC_NAME = "shm12";
this.STATIC_SHADOW_MC_NAME = "shStatic";
this.PAGE01_DEPTH = 8;
this.PAGE02_DEPTH = 5;
this.PAGE03_DEPTH = 4;
this.PAGE04_DEPTH = 0;
this.SH12_SCALE = 0.4;
this.SH3_SCALE = 1.6;
this.SPEED_DIV = 10;
}
function FFlippingBookBroker() {
this.objects = new Array();
}
FFlippingBookBroker.prototype.registerObject = function(id, obj) {
this.objects[id] = obj;
};
function FFlippingBookCache(broker, usePreloader, cachePages, loadOnDemand, bgColor) {
this._broker = broker;
this._const = new FFlippingBookConstants();
this._broker.registerObject(this._const.CACHE_OBJ_ID, this);
this._baseObject = this._broker.objects[this._const.MAIN_OBJ_ID];
this._pagesDepth = this._const.CACHE_DEPTH;
this.usePreloader = usePreloader;
this.cachePages = cachePages;
this.loadOnDemand = loadOnDemand;
this.bgColor = bgColor;
this.__pagesLinks = new Array();
this.__pagesProcess = new Array();
this.__pagesHolders = new Array();
this.__pagesLoaders = new Array();
this.__pagesTimeouts = new Array();
this.__pagesLoading = new Array();
this.__pagesExt = new Array();
this.__pagesDepths = new Array();
this.__pagesBacks = new Array();
this.__pagesMasks = new Array();
this.__checkCompleted = new Array();
this.__pagesShadows1 = new Array();
this.__pagesShadows2 = new Array();
this._sound = new Sound(this._baseObject);
this._isSound = true;
this._soundTimeout = this._const.MEDIA_TIMEOUT;
this.sd = this._baseObject.shadowsDepth;
this.ssd = this._baseObject.staticShadowsDepth;
this._mediaComplete = false;
this._soundComplete = false;
this._pagesComplete = false;
this.extXML = new XML();
this.extXML.ignoreWhite = true;
this.extXML._parentObj = this;
this.extXML.onLoad = this.onXMLComplete;
}
FFlippingBookCache.prototype._stripItem = function(str) {
var end = str.indexOf(this._const.DELIMITER)+this._const.DELIMITER.length;
return str.substr(end);
};
FFlippingBookCache.prototype.loadExternalXML = function(src) {
if (src != "") {
this.extXML.load(src);
} else {
this._baseObject._onXMLComplete(false);
}
};
FFlippingBookCache.prototype.onXMLComplete = function(success) {
if (success && this.status == 0) {
this._parentObj._baseObject._onXMLComplete();
} else if (this.status != 0) {
trace(this._parentObj._const.INVALID_XML_MSG);
}
};
FFlippingBookCache.prototype.loadMedia = function(pagesSet, flipSound, pageBack, w, h) {
this._soundSrc = flipSound;
this._bgColor = pageBack;
this._realPages = pagesSet;
this._pageWidth = w/2;
this._pageHeight = h;
this._loadFlipSound();
this._loadPages();
if (!this.loadOnDemand) {
this._baseObject.progress = 0;
this.__placeOverallPreloader();
}
this._mediaInterval = setInterval(this.__checkMedia, this._const.MEDIA_INTERVAL, this);
};
FFlippingBookCache.prototype._loadFlipSound = function() {
this._soundComplete = false;
if (this._soundSrc == this._const.DEF_NO_SOUND || this._soundSrc == undefined) {
this._isSound = false;
this._soundComplete = true;
} else {
this._sound.attachSound(this._soundSrc);
if (this._sound.duration == undefined) {
this._sound.loadSound(this._soundSrc, false);
}
this._soundComplete = false;
this._isSound = false;
}
};
FFlippingBookCache.prototype._getProgress = function() {
var p = 0;
var k = 0;
for (var src in this.__pagesProcess) {
if (this.__pagesExt[src]) {
if (!isNaN(this.__pagesProcess[src])) {
p += this.__pagesProcess[src];
}
k++;
}
}
return (p/k);
};
FFlippingBookCache.prototype.__checkMedia = function(obj) {
if (!obj._soundComplete) {
if (obj._sound.getBytesLoaded() == obj._sound.getBytesTotal() || obj._sound.getBytesTotal() == undefined) {
if (obj._sound.getBytesTotal == 0 && obj._soundTimeout>0) {
obj._soundTimeout -= obj._const.MEDIA_INTERVAL;
} else if (obj._sound.getBytesTotal == undefined && obj._soundTimeout<=0) {
obj._isSound = false;
obj._soundComplete = true;
} else {
obj._isSound = true;
obj._soundComplete = true;
}
}
}
if (!obj._pagesComplete && !obj.loadOnDemand) {
obj._pagesComplete = true;
for (src in obj.__pagesProcess) {
if (obj.__pagesProcess[src]<100 || obj.__checkCompleted[src] == 1 || isNaN(obj.__pagesProcess[src])) {
var pt = obj.__pagesHolders[src].getBytesLoaded()/obj.__pagesHolders[src].getBytesTotal()*100;
if (obj.usePreloader) {
obj.__pagesLoaders[src].setProgress(pt);
}
obj.__pagesProcess[src] = pt;
obj.__pagesHolders[src].progress = pt;
obj._baseObject.progress = obj._getProgress();
obj.preloader.setProgress(obj._baseObject.progress);
obj.__pagesTimeouts[src] -= obj._const.MEDIA_INTERVAL;
if (pt == 100 && obj.__pagesHolders[src].getBytesLoaded()>4 && obj.__checkCompleted[src] == 1) {
obj._baseObject._setPageParameters(obj.__pagesHolders[src], src, true);
obj.__pagesBacks[src]._visible = false;
obj._baseObject._setVisible();
obj.__pagesHolders[src].progress = 100;
obj.__pagesLoaders[src].removeMovieClip();
if (obj._baseObject.scaleContent) {
obj.__pagesHolders[src]._width = obj._pageWidth;
obj.__pagesHolders[src]._height = obj._pageHeight;
} else {
obj.__pagesHolders[src].setMask(obj.__pagesMasks[src]);
}
obj.__pagesHolders[src]._parent._visible = true;
obj.__pagesProcess[src] = pt;
if (obj._model == undefined) {
obj._model = obj._broker.objects[obj._const.MODEL_OBJ_ID];
}
obj._baseObject.onPageLoad(obj._stripItem(src), obj.__pagesHolders[src].pageNumber);
} else {
obj._pagesComplete = false;
}
if (pt == 100 && obj.__pagesHolders[src].getBytesLoaded()>4) {
obj.__checkCompleted[src] = 1;
}
}
}
}
if (obj._soundComplete && (obj._pagesComplete || obj.loadOnDemand)) {
clearInterval(obj._mediaInterval);
obj._baseObject._onMediaComplete();
if (obj._pagesComplete) {
obj._baseObject.progress = 100;
obj.preloader.removeMovieClip();
}
}
};
FFlippingBookCache.prototype._loadPages = function() {
var k = this._realPages.length;
for (var i = 0; i
if (this.__pagesLinks[this._realPages[i]] == undefined) {
this.__pagesLinks[this._realPages[i]] = this.__createPage(this._const.DEF_PAGE_NAME+"_"+i, this._realPages[i]);
this.__pagesLinks[this._realPages[i]]._y = -this._pageHeight/2;
this.__pagesLinks[this._realPages[i]]._visible = false;
}
}
for (src in this.__pagesLinks) {
this.__pagesLoading[src] = false;
var initObj = this._baseObject.pageParameters[this._baseObject.pageIndexes[src]];
var media = this.__pagesHolders[src].attachMovie(this._stripItem(src), this._const.PAGE_MEDIA_NAME, 0);
if (media == undefined && (src != this._const.TRANSPARENT_PAGE1) && (src != this._const.TRANSPARENT_PAGE2) && src != this._const.EMPTY_PAGE) {
var initObj = this._baseObject.pageParameters[this._baseObject.pageIndexes[src]];
this.__pagesHolders[src]._parent.params = new Object();
this.__pagesHolders[src]._parent.params = initObj;
this._baseObject._setPageParameters(this.__pagesHolders[src], src, false);
this.__pagesProcess[src] = 0;
this.__pagesExt[src] = true;
this.__pagesTimeouts[src] = this._const.PAGE_TIMEOUT;
if (!this.loadOnDemand) {
this.__pagesHolders[src]._parent._visible = false;
this.__pagesHolders[src].loadMovie(this._stripItem(src));
}
if (this.usePreloader) {
var loaderLnk = this.__pagesLinks[src];
this.__placePreloader(loaderLnk);
this.__pagesLoaders[src] = loaderLnk[this._const.PAGE_PRELOADER_NAME];
}
this.__pagesHolders[src].progress = 0;
} else {
this.__pagesExt[src] = false;
this.__pagesProcess[src] = 100;
this.__pagesHolders[src].progress = 100;
this.__pagesHolders[src].params = new Object();
this.__pagesHolders[src].params = initObj;
this._baseObject._setPageParameters(this.__pagesHolders[src].media, src, true);
this._baseObject._setVisible();
if( src != this._const.TRANSPARENT_PAGE1 && src != this._const.TRANSPARENT_PAGE2 && src != this._const.EMPTY_PAGE )
this.__pagesBacks[src]._visible = false;
if (this._baseObject.scaleContent) {
this.__pagesHolders[src]._width = this._pageWidth;
this.__pagesHolders[src]._height = this._pageHeight;
} else {
this.__pagesHolders[src].setMask(this.__pagesMasks[src]);
}
}
}
};
FFlippingBookCache.prototype.__createPage = function(src, id) {
var pageLnk = this._baseObject.createEmptyMovieClip(src, this._pagesDepth++);
var holderParent = pageLnk.createEmptyMovieClip(this._const.PAGE_HOLDER_PARENT_NAME, 1);
if (id != this._const.TRANSPARENT_PAGE1 && id != this._const.TRANSPARENT_PAGE2) {
var bgLnk = pageLnk.createEmptyMovieClip(this._const.PAGE_BG_NAME, 0);
var shadowLnk = pageLnk.createEmptyMovieClip(this._const.PAGE_SHADOW_LAYER_NAME, 100);
this.__drawBack(bgLnk);
this.__pagesBacks[id] = bgLnk;
if (id != this._const.EMPTY_PAGE) {
this.__pagesHolders[id] = holderParent.createEmptyMovieClip(this._const.PAGE_HOLDER_NAME, 0);
this.__pagesProcess[id] = 0;
if (!this._baseObject.scaleContent) {
this.__pagesMasks[id] = holderParent.createEmptyMovieClip(this._const.PAGE_MASK_NAME, 100);
this.__drawBack(this.__pagesMasks[id]);
}
} else {
this.__pagesProcess[id] = 100;
}
var sh1 = this.__pagesShadows1[id]=shadowLnk.createEmptyMovieClip(this._const.PAGE_STATIC_SHADOW1_NAME, 10);
var sh2 = this.__pagesShadows2[id]=shadowLnk.createEmptyMovieClip(this._const.PAGE_STATIC_SHADOW2_NAME, 11);
this.__drawStaticShadows(sh1, sh2);
} else {
this.__pagesHolders[id] = 100;
}
return pageLnk;
};
FFlippingBookCache.prototype.__drawStaticShadows = function(mc1, mc2) {
var pw = this._pageWidth;
var sw = pw/3;
var sh = this._pageHeight;
var colors = [0x000000, 0x000000];
var ratios = [0, 255];
var alphas = [0, 20*this.ssd];
var matrix = {matrixType:"box", x:pw-sw, y:0, w:sw, h:sh, r:0};
with (mc1) {
moveTo(pw-sw, 0);
beginGradientFill("linear", colors, alphas, ratios, matrix);
lineTo(pw, 0);
lineTo(pw, sh);
lineTo(pw-sw, sh);
lineTo(pw-sw, 0);
endFill();
}
colors = [0x000000, 0x000000];
ratios = [0, 255];
alphas = [20*this.ssd, 0];
matrix = {matrixType:"box", x:0, y:0, w:sw, h:sh, r:0};
with (mc2) {
moveTo(0, 0);
beginGradientFill("linear", colors, alphas, ratios, matrix);
lineTo(sw, 0);
lineTo(sw, sh);
lineTo(0, sh);
lineTo(0, 0);
endFill();
}
};
FFlippingBookCache.prototype.__placePreloader = function(mc) {
var loaderSymbolName;
switch (this._baseObject.preloaderType) {
case "Progress Bar" :
loaderSymbolName = "FBStandardPreloader";
break;
case "Round" :
loaderSymbolName = "FBRoundPreloader";
break;
case "User Defined" :
loaderSymbolName = this._baseObject.userPreloaderId;
break;
}
var loader = mc.attachMovie(loaderSymbolName, this._const.PAGE_PRELOADER_NAME, 2);
var cx = this._pageWidth/2;
var cy = this._pageHeight/2;
loader._x = Math.round(cx);
loader._y = Math.round(cy);
loader.setProgress(0);
};
FFlippingBookCache.prototype.__placeOverallPreloader = function() {
var loaderSymbolName;
switch (this._baseObject.preloaderType) {
case "Progress Bar" :
loaderSymbolName = "FBStandardPreloader";
break;
case "Round" :
loaderSymbolName = "FBRoundPreloader";
break;
case "User Defined" :
loaderSymbolName = this._baseObject.userPreloaderId;
break;
}
this.preloader = this._baseObject.createEmptyMovieClip("overall_preloader", 20);
this.preloader = this.preloader.attachMovie(loaderSymbolName, this._const.PAGE_PRELOADER_NAME, 2);
loader._x = 0;
loader._y = 0;
};
FFlippingBookCache.prototype.__drawBack = function(mc) {
with (mc) {
moveTo(0, 0);
beginFill(this.bgColor, 100);
lineTo(this._pageWidth, 0);
lineTo(this._pageWidth, this._pageHeight);
lineTo(0, this._pageHeight);
lineTo(0, 0);
endFill();
}
};
FFlippingBookCache.prototype.getPage = function(src) {
var page = this.__pagesLinks[src];
if (!this.loadOnDemand) {
return page;
}
if (!this.__pagesLoading[src] && this.__pagesProcess[src] == 0 || (!this.cachePages && this.__pagesExt[src] && this.__pagesProcess[src] == 100)) {
this.__pagesHolders[src]._parent._visible = false;
this.__pagesHolders[src].loadMovie(this._stripItem(src));
this.__pagesLoading[src] = true;
this.__pagesBacks[src]._visible = true;
this.__pagesLoaders[src]._visible = true;
if (!this._pagesInterval) {
this._pagesInterval = setInterval(this.__checkPages, this._const.MEDIA_INTERVAL, this);
}
}
return page;
};
FFlippingBookCache.prototype.__checkPages = function(obj) {
var complete = true;
for (src in obj.__pagesLoading) {
if (obj.__pagesLoading[src]) {
var pt = obj.__pagesHolders[src].getBytesLoaded()/obj.__pagesHolders[src].getBytesTotal()*100;
if (obj.usePreloader) {
obj.__pagesLoaders[src].setProgress(pt);
}
obj.__pagesTimeouts[src] -= obj._const.MEDIA_INTERVAL;
obj.__pagesProcess[src] = pt;
obj.__pagesHolders[src].progress = pt;
if (pt == 100 && obj.__pagesHolders[src].getBytesLoaded()>4 && obj.__checkCompleted[src] == 1 && !isNaN(pt)) {
obj._baseObject._setPageParameters(obj.__pagesHolders[src], src, true);
obj.__pagesBacks[src]._visible = false;
obj._baseObject._setVisible();
if (obj.cachePages) {
obj.__pagesLoaders[src]._visible = false;
obj.__pagesProcess[src] = 100;
} else {
obj.__pagesLoaders[src]._visible = false;
obj.__pagesLoaders[src].setProgress(0);
obj.__checkCompleted[src] = undefined;
}
if (obj._baseObject.scaleContent) {
obj.__pagesHolders[src]._width = obj._pageWidth;
obj.__pagesHolders[src]._height = obj._pageHeight;
} else {
obj.__pagesHolders[src].setMask(obj.__pagesMasks[src]);
}
obj.__pagesHolders[src]._parent._visible = true;
obj.__pagesLoading[src] = false;
if (obj._model == undefined) {
obj._model = obj._broker.objects[obj._const.MODEL_OBJ_ID];
}
obj._baseObject.onPageLoad(obj._stripItem(src), obj.__pagesHolders[src].pageNumber);
} else {
complete = false;
}
if (pt == 100 && obj.__pagesHolders[src].getBytesLoaded()>4) {
obj.__checkCompleted[src] = 1;
}
}
}
if (complete) {
clearInterval(obj._pagesInterval);
obj._pagesInterval = undefined;
}
};
FFlippingBookCache.prototype.setPage = function(page, src, i, pageNum, dir) {
if (this._baseObject.loadOnDemand) {
if (i == 1 || i == 3) {
var cacheVolume = this._baseObject.cacheSize;
var pagesForLoad = new Array();
var pagesForUnload = new Array();
var maxPage = this._baseObject._model._realPages.length;
var g = 0;
for (var k = pageNum-cacheVolume; k<=pageNum+cacheVolume; k++) {
if ((k>=0) && (k
pagesForLoad[g++] = k;
}
}
var k1 = pagesForLoad[0];
var k2 = pagesForLoad[g-1];
var g = 0;
for (var k = 0; k
var vsrc = this._baseObject._model._realPages[k];
if (((kk2)) && this.__pagesExt[vsrc] && (this.__pagesLoading[vsrc] || this.__checkCompleted[vsrc] == 1)) {
pagesForUnload[g++] = k;
}
}
for (var p = 0; p
var vsrc = this._baseObject._model._realPages[pagesForLoad[p]];
if (this.__pagesExt[vsrc] && !this.__pagesLoading[vsrc] && this.__pagesProcess[vsrc] == 0) {
this.getPage(vsrc);
this.__pagesLoading[vsrc] = true;
}
}
for (var p = 0; p
if (pagesForUnload[p]>0 && pagesForUnload[p]
var vsrc = this._baseObject._model._realPages[pagesForUnload[p]];
this.__pagesProcess[vsrc] = 0;
this.__pagesLoading[vsrc] = false;
this.__checkCompleted[vsrc] = 0;
var pn = this.__pagesHolders[vsrc].pageNumber;
this.__pagesHolders[vsrc].loaded = false;
unloadMovie(this.__pagesHolders[vsrc]);
this._baseObject.onPageUnload(pn);
}
}
}
}
if (this._view == undefined) {
this._view = this._broker.objects[this._const.VIEW_OBJ_ID];
}
var cachePage_mc = this.getPage(src);
var targetPage_mc = page;
this.__pagesDepths[i] = cachePage_mc.getDepth();
targetPage_mc.swapDepths(cachePage_mc);
cachePage_mc._x = targetPage_mc._x;
cachePage_mc._y = targetPage_mc._y;
cachePage_mc._rotation = targetPage_mc._rotation;
targetPage_mc._visible = false;
if (i<3) {
cachePage_mc._visible = true;
}
if ((i == 1 || i == 2) && (src == this._const.TRANSPARENT_PAGE1 || src == this._const.TRANSPARENT_PAGE2)) {
this._view._transpPage = i;
}
if (i == 4 && (src == this._const.TRANSPARENT_PAGE1 || src == this._const.TRANSPARENT_PAGE2)) {
this._view._transpPage04 = true;
} else {
this._view._transpPage04 = false;
}
switch (i) {
case 1 :
this._view.__page01 = cachePage_mc;
this.__pagesShadows1[src]._visible = true;
this.__pagesShadows2[src]._visible = false;
break;
case 2 :
this._view.__page02 = cachePage_mc;
this.__pagesShadows1[src]._visible = false;
this.__pagesShadows2[src]._visible = true;
break;
case 3 :
this._view.__page03 = cachePage_mc;
if (this._view.__ox>0) {
this.__pagesShadows1[src]._visible = true;
this.__pagesShadows2[src]._visible = false;
} else {
this.__pagesShadows1[src]._visible = false;
this.__pagesShadows2[src]._visible = true;
}
break;
case 4 :
this._view.__page04 = cachePage_mc;
if (this._view.__ox<0) {
this.__pagesShadows1[src]._visible = true;
this.__pagesShadows2[src]._visible = false;
} else {
this.__pagesShadows1[src]._visible = false;
this.__pagesShadows2[src]._visible = true;
}
break;
}
};
FFlippingBookCache.prototype.setSize = function(w, h) {
this._pageWidth = w/2;
this._pageHeight = h;
for (link in this.__pagesHolders) {
if (this._baseObject.scaleContent && this.__pagesProcess[link] == 100) {
this.__pagesHolders[link]._width = w/2;
this.__pagesHolders[link]._height = h;
}

if( this.__pagesHolders[link]._parent._parent._x < 0 )
this.__pagesHolders[link]._parent._parent._x = -w/2;

this.__pagesHolders[link]._parent._parent._y = -h/2;
}
for (id in this.__pagesShadows1) {
this.__pagesShadows1[id]._width = w/6;
this.__pagesShadows1[id]._height = h;
}
for (id in this.__pagesShadows2) {
this.__pagesShadows2[id]._width = w/6;
this.__pagesShadows2[id]._height = h;
}
for (id in this.__pagesBacks) {
this.__pagesBacks[id]._width = w/2;
this.__pagesBacks[id]._height = h;
}
for (id in this.__pagesLoaders) {
var loader = this.__pagesLoaders[id];
var cx = w/4;
var cy = h/2;
loader._x = cx;
loader._y = cy;
}
for (mask in this.__pagesMasks) {
this.__pagesMasks[mask]._width = w/2;
this.__pagesMasks[mask]._height = h;
}
};
FFlippingBookCache.prototype.restoreDirectGotoPages = function() {
this._view.__page01.setMask(null);
this._view.__page02.setMask(null);
this._view.__mask12.clear();
this._view.__page01._visible = false;
this._view.__page02._visible = false;
this._view.__page01.swapDepths(this.__pagesDepths[1]);
this._view.__page02.swapDepths(this.__pagesDepths[2]);
this._view.__page01 = this._view.tmp01;
this._view.__page02 = this._view.tmp02;
this._view._transpPage = 0;
};

FFlippingBookCache.prototype.showUnderlyingPages = function(direction, _pageNumber){
var book = this._baseObject;
var l = book.leftPageNumber;
var r = book.rightPageNumber;
var t = book.totalPages;
var isGotoPage = (book._view._bookState == book._constants.GOTOPAGE_STATE);
if( isGotoPage && direction == undefined ) return;
if( !this.misNaN( this.lv_n ) && this.lv_n != l && !(isGotoPage && this.lv_n == (l-2))){
var page = book.getPageLink( this.lv_n );
if( page._parent.media != undefined )page = page._parent;
var holder = page._parent._parent;
holder._visible = false;
}

if( !this.misNaN( this.rv_n ) && this.rv_n != r && !(isGotoPage && this.rv_n == (r + 2))){
var page = book.getPageLink( this.rv_n );
if( page._parent.media != undefined )page = page._parent;
var holder = page._parent._parent;
holder._visible = false;
}
this.lv_n = this.rv_n = undefined;
if( l != undefined && (l - 2) >= 0 ) this.lv_n = l - 2;
if( r != undefined && (l + 2) <= (t-1) ) this.rv_n = r + 2;

if( direction == "left" )this.lv_n = _pageNumber;
else if(direction == "right" )this.rv_n = _pageNumber;

if( !this.misNaN(this.lv_n) ){
var page = book.getPageLink( this.lv_n );
if( page._parent.media != undefined )page = page._parent;
var holder = page._parent._parent;
holder._visible = true;
holder._x = -this._pageWidth;
holder.shadows.STATICSH2._visible = false;
}
if( !this.misNaN(this.rv_n) ){
var page = book.getPageLink( this.rv_n );
if( page._parent.media != undefined )page = page._parent;
var holder = page._parent._parent;
holder._visible = true;
holder._x = 0;
holder.shadows.STATICSH1._visible = false;
}
}
FFlippingBookCache.prototype.misNaN = function(val) {
if(isNaN( val ) ||( val == undefined) )return true;
else return false;
}
FFlippingBookCache.prototype.restorePages = function() {
this._view.__page01.setMask(null);
this._view.__page02.setMask(null);
this._view.__page03.setMask(null);
this._view.__page04.setMask(null);
this._view._drawShadow03();
this._view.__mask03.clear();
this._view.__mask12.clear();
this._view.__page01._visible = false;
this._view.__page02._visible = false;
this._view.__page01.swapDepths(this.__pagesDepths[1]);
this._view.__page02.swapDepths(this.__pagesDepths[2]);
this._view.__page03.swapDepths(this.__pagesDepths[3]);
this._view.__page04.swapDepths(this.__pagesDepths[4]);
this._view.__page03._x = -this._view._pageWidth;
this._view.__page03._y = -this._view._pageHeight/2;
this._view.__page03._rotation = 0;
this._view.__page04._x = 0;
this._view.__page04._y = -this._view._pageHeight/2;
this._view.__page04._rotation = 0;
this._view.__page01 = this._view.tmp01;
this._view.__page02 = this._view.tmp02;
this._view.__page03 = this._view.tmp03;
this._view.__page04 = this._view.tmp04;
this._view._transpPage = 0;
};
FFlippingBookCache.prototype.restoreWorkPages = function() {
this._view.__page01.setMask(null);
this._view.__page02.setMask(null);
this._view.__mask03.clear();
this._view.__mask12.clear();
this._view._drawShadow12();
this._view._drawShadow03();
this._view._drawShadow04();
this._view.__page03._visible = false;
this._view.__page04._visible = false;
this._view.__page03.swapDepths(this.__pagesDepths[3]);
this._view.__page04.swapDepths(this.__pagesDepths[4]);
this._view.__page03._x = -this._view._pageWidth;
this._view.__page03._y = -this._view._pageHeight/2;
this._view.__page03._rotation = 0;
this._view.__page04._x = 0;
this._view.__page04._y = -this._view._pageHeight/2;
this._view.__page04._rotation = 0;
this._view.__page03 = this._view.tmp03;
this._view.__page04 = this._view.tmp04;
this.showUnderlyingPages();
};
function FFlippingBookModel(pagesSet, firstPage, alwaysOpened, broker) {
this._broker = broker;
this._const = new FFlippingBookConstants();
this._broker.registerObject(this._const.MODEL_OBJ_ID, this);
this._cache = this._broker.objects[this._const.CACHE_OBJ_ID];
this._baseObj = this._broker.objects[this._const.MAIN_OBJ_ID];
this._userPages = pagesSet;
this._curPageNumbers = new Array(4);
this._markEqual();
this._realPages = this._copyArray(pagesSet);
this.alwaysOpened = alwaysOpened;
this.__direction = -1;
this._makeItReal();
this.addProperty("_userCurrentPage2", this.getUserCurrentPage2, null);
this._userCurrentPage = firstPage;
this._currentPage = this._realPageNumber(firstPage);
}
FFlippingBookModel.prototype.getUserPageNumber = function(src) {
var len = this._userPages.length;
for (var i = 0; i
var item = this._userPages[i];
if (item == src) {
return i;
}
}
if (src == this._const.EMPTY_PAGE) {
return len;
}
};
FFlippingBookModel.prototype._markEqual = function() {
var delimiter = this._const.DELIMITER;
var len = this._userPages.length;
var marked = new Array(len);
for (var k = 0; k
marked[k] = false;
}
for (var i = 0; i
var curItem = this._userPages[i];
var curIndex = i;
var count = 0;
for (var j = 0; j
var compItem = this._userPages[j];
if (compItem == curItem && !marked[j]) {
this._userPages[j] = count+++delimiter+this._userPages[j];
marked[j] = true;
}
}
}
};
FFlippingBookModel.prototype.getUserCurrentPage2 = function() {
var k = this._userCurrentPage;

if (this._view.__ox>0) {
k += 1;
}
return k;
};
FFlippingBookModel.prototype.__addPage = function(index, pageSrc) {
this._realPages.splice(index, 0, pageSrc);
};
FFlippingBookModel.prototype._copyArray = function(src) {
var res = new Array();
for (var j = 0; j
res[j] = src[j];
}
return res;
};
FFlippingBookModel.prototype._makeItReal = function() {
this._realPages = this._copyArray(this._userPages);
var odd = true;
if (this._realPages.length%2 == 0) {
odd = false;
}
if (odd) {
this.__addPage(this._realPages.length, this._const.EMPTY_PAGE);
}
if (!this.alwaysOpened) {
this.__addPage(0, this._const.TRANSPARENT_PAGE1);
this.__addPage(this._realPages.length, this._const.TRANSPARENT_PAGE2);
}
};
FFlippingBookModel.prototype._realPageNumber = function(n) {
if (n<0) {
n = 0;
} else if (n>=this._userPages.length) {
n = this._userPages.length-1;
if (!this.alwaysOpened && this._userPages.length%2 != 0) {
n++;
}
}
if (!this.alwaysOpened) {
n++;
}
if (this._userPages.length == 0) {
n = 0;
}
if (n%2 != 0) {
n--;
}
return n;
};
FFlippingBookModel.prototype.putPage = function(isDirect, direct_dir) {
if (this._view == undefined) {
this._view = this._broker.objects[this._const.VIEW_OBJ_ID];
}
var dir = this.__direction;
this.__direction = -1;
switch (dir) {
case 0 :
this._currentPage -= 2;
this._userCurrentPage -= 2;
break;
case 1 :
this._currentPage += 2;
this._userCurrentPage += 2;
break;
}
this._cache.setPage(this._view.__page01, this._realPages[this._currentPage], 1, this._currentPage, dir);
this._cache.setPage(this._view.__page02, this._realPages[this._currentPage+1], 2, this._currentPage+1, dir);
this._curPageNumbers[0] = this.getUserPageNumber(this._realPages[this._currentPage]);
this._curPageNumbers[1] = this.getUserPageNumber(this._realPages[this._currentPage+1]);
if (this._realPages[this._currentPage] == this._const.EMPTY_PAGE) {
this._curPageNumbers[0] = this._userPages.length;
}
vsrc = this._baseObj.pagesSet[this._userCurrentPage];
if (this._view._bookState != this._const.FLIP_GOTOPAGE_STATE) {
if (dir == 1) {
this._baseObj._setVisible();
if (this._cache.__pagesExt[vsrc] == true) {
this._baseObj.onPutPage(this._curPageNumbers[0], this._cache.__pagesHolders[this._userPages[this._curPageNumbers[0]]]);
} else {
this._baseObj.onPutPage(this._curPageNumbers[0], this._cache.__pagesHolders[this._userPages[this._curPageNumbers[0]]].media);
}
} else {
var tmp_holder = this._cache.__pagesHolders[this._userPages[this._curPageNumbers[1]]];
if (isDirect && (direct_dir == 1)) {
tmp_holder = this._cache.__pagesHolders[this._userPages[this._curPageNumbers[0]]];
}
if (this._cache.__pagesExt[vsrc] == false) {
tmp_holder = tmp_holder.media;
}
var tmp_cp = this._curPageNumbers[1];
if (tmp_cp == undefined) {
tmp_cp = this._curPageNumbers[0]+1;
}
if (isDirect && (direct_dir == 1)) {
tmp_cp--;
}
if (!(tmp_cp%2)) {
this._userCurrentPage = tmp_cp;
} else {
if (this._baseObj.alwaysOpened) {
this._userCurrentPage = tmp_cp-1;
} else {
this._userCurrentPage = tmp_cp+1;
}
}
this._baseObj._setVisible();
this._baseObj.onPutPage(tmp_cp, tmp_holder);
}
}
this._view.onSetPages(1, 2);
if (this._currentPage+2>this._realPages.length-1) {
this._baseObj.onLastPage();
} else if (this._currentPage-2<0) {
this._baseObj.onFirstPage();
}
this._cache.showUnderlyingPages();
};
FFlippingBookModel.prototype.flipGotoForward = function(n) {
var a = n-this._currentPage;
if (this._currentPage != this._realPages.length-2 && this._currentPage>=0) {
this._cache.setPage(this._view.__page03, this._realPages[this._currentPage+a], 3, this._currentPage+a, 1);
this._cache.setPage(this._view.__page04, this._realPages[this._currentPage+a+1], 4, this._currentPage+a+1, 1);
this._curPageNumbers[2] = this.getUserPageNumber(this._realPages[this._currentPage+a]);
this._curPageNumbers[3] = this.getUserPageNumber(this._realPages[this._currentPage+a+1]);
this.__direction = 1;
if( this._curPageNumbers[3] == undefined )
var vcp = undefined;
else
var vcp = this._curPageNumbers[3] + 2;
this._cache.showUnderlyingPages("right", vcp);
} else {
this._view._bookState = this._const.UNACTIVE_STATE;
}
};
FFlippingBookModel.prototype.goForward = function() {
if (this._currentPage != this._realPages.length-2 && this._currentPage>=0) {
this._cache.setPage(this._view.__page03, this._realPages[this._currentPage+2], 3, this._currentPage+2, 1);
this._cache.setPage(this._view.__page04, this._realPages[this._currentPage+3], 4, this._currentPage+3, 1);
this._curPageNumbers[2] = this.getUserPageNumber(this._realPages[this._currentPage+2]);
this._curPageNumbers[3] = this.getUserPageNumber(this._realPages[this._currentPage+3]);
this._cache.showUnderlyingPages("right", this._baseObj.rightPageNumber + 4);
this.__direction = 1;
} else {
this._view._bookState = this._const.UNACTIVE_STATE;
}
};
FFlippingBookModel.prototype.flipGotoBack = function(n) {
var a = this._currentPage - n - 1;

if (this._currentPage>0) {
this._cache.setPage(this._view.__page03, this._realPages[this._currentPage-a], 3, this._currentPage-a, 0);
this._cache.setPage(this._view.__page04, this._realPages[this._currentPage-a-1], 4, this._currentPage-a-1, 0);
this._curPageNumbers[2] = this.getUserPageNumber(this._realPages[this._currentPage-a]);
this._curPageNumbers[3] = this.getUserPageNumber(this._realPages[this._currentPage-a-1]);
this.__direction = 0;

if( this._curPageNumbers[3] == undefined )
var vcp = undefined;
else
var vcp = this._curPageNumbers[3] - 2;
this._cache.showUnderlyingPages("left", vcp);
} else {
this._view._bookState = this._const.UNACTIVE_STATE;
}
};
FFlippingBookModel.prototype.goBack = function() {
if (this._currentPage>0) {
this._cache.setPage(this._view.__page03, this._realPages[this._currentPage-1], 3, this._currentPage-1, 0);
this._cache.setPage(this._view.__page04, this._realPages[this._currentPage-2], 4, this._currentPage-2, 0);
this._curPageNumbers[2] = this.getUserPageNumber(this._realPages[this._currentPage-1]);
this._curPageNumbers[3] = this.getUserPageNumber(this._realPages[this._currentPage-2]);
this._cache.showUnderlyingPages("left", this._baseObj.leftPageNumber - 4);
this.__direction = 0;
} else {
this._view._bookState = this._const.UNACTIVE_STATE;
}
};
FFlippingBookModel.prototype.getFlipGotoPage = function(n, state) {
if (state) {
this._view._bookState = this._const.UNACTIVE_STATE;
this._currentPage = this._last_current_page;
this._view.directGotoPage(n);
return;
}
if (this._currentPage>n) {
this.flipGotoBack(n);
} else if (this._currentPage
this.flipGotoForward(n);
} else {
this._view._bookState = this._const.UNACTIVE_STATE;
}
};
FFlippingBookModel.prototype.getNextGotoPage = function(n) {
if (this._currentPage>n) {
this.goBack();
} else if (this._currentPage
this.goForward();
} else {
this._baseObj.onEndGoto();
this._view._bookState = this._const.UNACTIVE_STATE;
}
};
function FFlippingBookClass() {
this._constants = new FFlippingBookConstants();
this._broker = new FFlippingBookBroker();
this._broker.registerObject(this._constants.MAIN_OBJ_ID, this);
this.usePreloader = (this.preloaderType != "None");
this._cache = new FFlippingBookCache(this._broker, this.usePreloader, this.cachePages, this.loadOnDemand, this.pageBack);
this.pageParameters = new Array();
this.pageIndexes = new Array();
this.addProperty("enabledProp", this.getEnabledProp, this.setEnabledProp);
this.addProperty("totalPages", this.getTotalPages, null);
this.addProperty("leftPageNumber", this.getLeftPageNumber, null);
this.addProperty("rightPageNumber", this.getRightPageNumber, null);
this.addProperty("autoFlipProp", this.getAutoFlipProp, this.setAutoFlipProp);
this.addProperty("flipOnClickProp", this.getFlipOnClick, this.setFlipOnClick);
this.addProperty("moveSpeedProp", this.getMoveSpeedProp, this.setMoveSpeedProp);
this.addProperty("closeSpeedProp", this.getCloseSpeedProp, this.setCloseSpeedProp);
this.addProperty("gotoSpeedProp", this.getGotoSpeedProp, this.setGotoSpeedProp);
this.addProperty("width", this.getWidth, this.setWidth);
this.addProperty("height", this.getHeight, this.setHeight);
this.addProperty("alwaysOpenedProp", this.getAlwaysOpenedProp, null);
this.enabledProp = true;
this._a = Math.abs(this._rotation/180*Math.PI);
this._sina = Math.sin(this._a);
this._cosa = Math.cos(this._a);
this._W = this._width;
this._H = this._height;
this._w = (this._H*this._sina-this._W*this._cosa)/(this._sina*this._sina-this._cosa*this._cosa);
this._h = (this._H*this._cosa-this._W*this._sina)/(this._cosa*this._cosa-this._sina*this._sina);
this.setSize(this._w, this._h);
this.box_mc._visible = false;
if (this.extXML != "") {
this._cache.loadExternalXML(this.extXML);
} else {
this._getMedia();
}
}
FFlippingBookClass.prototype = new MovieClip();
FFlippingBookClass.prototype.getEnabledProp = function() {
return this.enabled;
};
FFlippingBookClass.prototype.setEnabledProp = function(v) {
this.enabled = v;
};
FFlippingBookClass.prototype.getTotalPages = function() {
return this.pagesSet.length;
};
FFlippingBookClass.prototype.getLeftPageNumber = function() {
var pn = 0;
if (this.alwaysOpened) {
pn = this._model._userCurrentPage;
} else {
pn = this._model._userCurrentPage-1;
}
if (pn<0) {
pn = undefined;
}
return pn;
};
FFlippingBookClass.prototype.getRightPageNumber = function() {
var pn = 0;
if (!this.alwaysOpened) {
pn = this._model._userCurrentPage;
} else {
pn = this._model._userCurrentPage+1;
}
if (pn>=this.totalPages) {
pn = undefined;
}
return pn;
};
FFlippingBookClass.prototype.getAlwaysOpenedProp = function() {
return this.alwaysOpened;
};
FFlippingBookClass.prototype.getAutoFlipProp = function() {
return this.autoFlip;
};
FFlippingBookClass.prototype.setAutoFlipProp = function(v) {
this.autoFlip = v;
if (this._view != undefined) {
this._view._autoFlip = v;
}
};
FFlippingBookClass.prototype.getFlipOnClick = function() {
return this.flipOnClick;
};
FFlippingBookClass.prototype.setFlipOnClick = function(v) {
this.flipOnClick = v;
if (this._view != undefined) {
this._view._flipOnClick = v;
}
};
FFlippingBookClass.prototype.getMoveSpeedProp = function() {
return this.moveSpeed;
};
FFlippingBookClass.prototype.setMoveSpeedProp = function(v) {
this.moveSpeed = v;
if (this._view != undefined) {
this._view._pageSpeed = v/this._constants.SPEED_DIV;
}
};
FFlippingBookClass.prototype.getCloseSpeedProp = function() {
return this.closeSpeed;
};
FFlippingBookClass.prototype.setCloseSpeedProp = function(v) {
this.closeSpeed = v;
if (this._view != undefined) {
this._view._closeSpeed = v/this._constants.SPEED_DIV;
}
};
FFlippingBookClass.prototype.getGotoSpeedProp = function() {
return this.gotoSpeed;
};
FFlippingBookClass.prototype.setGotoSpeedProp = function(v) {
this.gotoSpeed = v;
if (this._view != undefined) {
this._view._gotoSpeed = v/this._constants.SPEED_DIV;
}
};
FFlippingBookClass.prototype.getWidth = function() {
return this._bookWidth;
};
FFlippingBookClass.prototype.setWidth = function(w) {
var h = this._bookHeight;
this.setSize(w, h);
};
FFlippingBookClass.prototype.getHeight = function() {
return this._bookHeight;
};
FFlippingBookClass.prototype.setHeight = function(h) {
var w = this._bookWidth;
this.setSize(w, h);
};
FFlippingBookClass.prototype.getPageLink = function(pageNumber) {
var src = this.pagesSet[pageNumber];
if (this._cache.__pagesExt[src]) {
return this._cache.__pagesHolders[src];
} else {
return this._cache.__pagesHolders[src].media;
}
};
FFlippingBookClass.prototype.isPageVisible = function(pageNumber) {
var page = this.getPageLink(pageNumber);
return page.visible;
};
FFlippingBookClass.prototype.isPageLoaded = function(pageNumber) {
var page = this.getPageLink(pageNumber);
return page.loaded;
};
FFlippingBookClass.prototype.getPageURL = function(pageNumber) {
var page = this.getPageLink(pageNumber);
return page.URL;
};
FFlippingBookClass.prototype.getPageParams = function(pageNumber) {
var page = this.getPageLink(pageNumber);
return page.params;
};
FFlippingBookClass.prototype.isLeftPage = function(pageNumber) {
var page = this.getPageLink(pageNumber);
return page.isLeftPage;
};
FFlippingBookClass.prototype.isRightPage = function(pageNumber) {
var page = this.getPageLink(pageNumber);
return page.isRightPage;
};
FFlippingBookClass.prototype.flipCorner = function(cornerPosition) {
if (this._view != undefined) {
this._view.flipCorner(cornerPosition);
}
};
FFlippingBookClass.prototype.flipForward = function() {
if (this._view != undefined) {
var i = this._model._currentPage+2;
this._view.gotoPage(i);
}
};
FFlippingBookClass.prototype.flipBack = function() {
if (this._view != undefined) {
var i = this._model._currentPage-2;
this._view.gotoPage(i);
}
};
FFlippingBookClass.prototype.setSize = function(w, h) {
this._bookWidth = w;
this._bookHeight = h;
this._xscale = 100;
this._yscale = 100;
if (this._view != undefined && (this._view._bookState == this._constants.UNACTIVE_STATE || this._view._bookState == this._constants.INIT_STATE)) {
this._view.setSize(w, h);
}
this._cache.setSize(w, h);
var holders = this._cache.__pagesHolders;
for (var src in holders) {
var page_mc = holders[src];
if (page_mc.media != undefined) {
page_mc = page_mc.media;
}
this._setPageParameters(page_mc, src, page_mc.loaded);
}
};
FFlippingBookClass.prototype._initLibraryPages = function() {
if (this.__alreadyInitialized) {
return;
}
var holders = this._cache.__pagesHolders;
for (var src in holders) {
var page_mc = holders[src].media;
if (page_mc) {
page_mc.onInit();
page_mc.onPageLoad();
this.onPageLoad(page_mc.URL, page_mc.pageNumber);
}
}
this.__alreadyInitialized = true;
};
FFlippingBookClass.prototype._setPageParameters = function(page_mc, src, isLoaded) {
page_mc.params = this.pageParameters[this.pageIndexes[src]];
page_mc.isExternal = this._cache.__pagesExt[src];
page_mc.book = this;
page_mc.URL = this._cache._stripItem(src);
page_mc.pageNumber = this.pageIndexes[src];
if (!page_mc.loaded && isLoaded) {
page_mc.onPageLoad();
}
page_mc.loaded = isLoaded;
if (page_mc.visible == undefined) {
page_mc.visible = false;
}
page_mc.width = this._bookWidth/2;
page_mc.height = this._bookHeight;
var isLeftPage = false;
var pn = page_mc.pageNumber;
if ((this.alwaysOpened && !(pn%2)) || (!this.alwaysOpened && (pn%2))) {
isLeftPage = true;
}
page_mc.isLeftPage = isLeftPage;
page_mc.isRightPage = !isLeftPage;

if( page_mc.isExternal == false ){
page_mc.__holder = page_mc._parent._parent._parent;
}
else{
page_mc.__holder = page_mc._parent._parent;
}
page_mc.onInit();
};
FFlippingBookClass.prototype._setVisible = function() {
var n = this.totalPages;
for (var i = 0; i
var page = this.getPageLink(i);
if (page.visible && page.pageNumber != this.leftPageNumber && page.pageNumber != this.rightPageNumber) {
page.visible = false;
page.onClose();
}
}
var leftPage = this.getPageLink(this.leftPageNumber);
var rightPage = this.getPageLink(this.rightPageNumber);
if (!leftPage.visible) {
leftPage.visible = true;
if (leftPage.onOpen) {
leftPage.onOpen();
leftPage.onOpenCalled = true;
}
}
if (!rightPage.visible) {
rightPage.visible = true;
if (rightPage.onOpen) {
rightPage.onOpen();
rightPage.onOpenCalled = true;
}
}
};
FFlippingBookClass.prototype._onXMLComplete = function() {
this._initFromCachedXML();
this._getMedia();
this.onXMLComplete();
};
FFlippingBookClass.prototype._getMedia = function() {
var end = this.pagesSet.length;
for (var i = 0; i
var pageURL = this.pagesSet[i];
if (pageURL.indexOf("?") != -1) {
this.pageParameters[i] = new Object();
var paramStr = pageURL.substr(pageURL.indexOf("?")+1, pageURL.length);
var filePath = pageURL.slice(0, pageURL.indexOf("?"));
this.pagesSet[i] = filePath;
do {
var varName = paramStr.substr(0, paramStr.indexOf("="));
var clauseEnd = (paramStr.indexOf("&") == -1) ? paramStr.length : (paramStr.indexOf("&"));
var varValue = paramStr.slice(paramStr.indexOf("=")+1, clauseEnd);
this.pageParameters[i][varName] = varValue;
if (paramStr.indexOf("&") == -1) {
paramStr = "";
}
paramStr = paramStr.substr(paramStr.indexOf("&")+1, paramStr.length);
} while (paramStr.indexOf("=") != -1);
}
}
this._model = new FFlippingBookModel(this.pagesSet, this.firstPage, this.alwaysOpened, this._broker);
for (var i = 0; i
this.pageIndexes[this.pagesSet[i]] = i;
}
this._cache.loadMedia(this._model._realPages, this.flipSound, this.pageBack, this._bookWidth, this._bookHeight);
};
FFlippingBookClass.prototype._onMediaComplete = function() {
if (this._model._userPages.length>0) {
this._view = new FFlippingBookView(this._bookWidth, this._bookHeight, this.autoFlip, this.flipOnClick, this._broker);
}
this.onInit();
};
FFlippingBookClass.prototype._initFromCachedXML = function() {
var extXML = this._cache.extXML;
var rootNode = extXML.firstChild;
var parameters = rootNode.childNodes;
var j = 0;
while (parameters[j]) {
var nodeName = parameters[j].nodeName.toUpperCase();
switch (nodeName) {
case this._constants.WIDTH_NODE_NAME :
this._bookWidth = parameters[j].firstChild.nodeValue;
break;
case this._constants.HEIGHT_NODE_NAME :
this._bookHeight = parameters[j].firstChild.nodeValue;
break;
case this._constants.FIRST_PAGE_NODE_NAME :
this.firstPage = parameters[j].firstChild.nodeValue;
break;
case this._constants.ALWAYS_OPENED_NODE_NAME :
this.alwaysOpened = parameters[j].firstChild.nodeValue;
break;
case this._constants.AUTOFLIP_NODE_NAME :
this.autoFlip = parameters[j].firstChild.nodeValue;
break;
case this._constants.FLIP_ON_CLICK_NODE_NAME :
this.flipOnClick = parameters[j].firstChild.nodeValue;
break;
case this._constants.SCALE_CONTENT_NODE_NAME :
this.scaleContent = parameters[j].firstChild.nodeValue;
break;
case this._constants.MOVE_SPEED_NODE_NAME :
this.moveSpeed = parameters[j].firstChild.nodeValue;
break;
case this._constants.CLOSE_SPEED_NODE_NAME :
this.closeSpeed = parameters[j].firstChild.nodeValue;
break;
case this._constants.GOTO_SPEED_NODE_NAME :
this.gotoSpeed = parameters[j].firstChild.nodeValue;
break;
case this._constants.FLIP_SOUND_NODE_NAME :
this.flipSound = this._removeWhite(parameters[j].firstChild.nodeValue);
break;
case this._constants.PAGE_BACK_NODE_NAME :
this.pageBack = parameters[j].firstChild.nodeValue;
break;
case this._constants.LOAD_ON_DEMAND_NODE_NAME :
this.loadOnDemand = parameters[j].firstChild.nodeValue;
break;
case this._constants.CACHE_PAGES_NODE_NAME :
this.cachePages = parameters[j].firstChild.nodeValue;
break;
case this._constants.USE_PRELOADER_NODE_NAME :
this.usePreloader = parameters[j].firstChild.nodeValue;
break;
case this._constants.STATIC_SHADOWS_DEPTH_NODE_NAME :
this.staticShadowsDepth = parameters[j].firstChild.nodeValue;
break;
case this._constants.DYNAMIC_SHADOWS_DEPTH_NODE_NAME :
this.shadowsDepth = parameters[j].firstChild.nodeValue;
break;
case this._constants.PRELOADER_TYPE_NODE_NAME :
this.preloaderType = parameters[j].firstChild.nodeValue;
break;
case this._constants.CACHE_SIZE_NODE_NAME :
this.cacheSize = parameters[j].firstChild.nodeValue;
break;
case this._constants.USER_PRELOADER_NODE_NAME :
this.userPreloaderId = parameters[j].firstChild.nodeValue;
break;
case this._constants.PAGES_NODE_NAME :
var i = 0;
var pages = parameters[j].childNodes;
this.pagesSet = new Array();
while (pages[i]) {
var curPage = this._removeWhite(pages[i].firstChild.nodeValue);
this.pagesSet.push(curPage);
i++;
}
break;
}
j++;
}
this._validateParameters();
};
FFlippingBookClass.prototype._removeWhite = function(str) {
var res = str;
while (res.charAt(0) == " ") {
res = res.substr(1, res.length);
}
while (res.charAt(res.length-1) == " ") {
res = res.substr(0, res.length-1);
}
return res;
};
FFlippingBookClass.prototype._validateNumber = function(param, min, max, def) {
if (typeof param != this._constants.NUM_TYPE_NAME) {
param = this._removeWhite(param);
if (!isNaN(Number(param))) {
param = Number(param);
} else {
param = def;
}
}
if (param>max) {
param = max;
}
if (param
param = min;
}
return param;
};
FFlippingBookClass.prototype._validateBoolean = function(param, def) {
if (typeof param != this._constants.BOOL_TYPE_NAME) {
param = param.toUpperCase();
if (param.indexOf(this._constants.BOOL_TRUE_VAL) != -1) {
param = true;
} else if (param.indexOf(this._constants.BOOL_FALSE_VAL) != -1) {
param = false;
} else {
param = def;
}
}
return param;
};
FFlippingBookClass.prototype._validateColor = function(param) {
param = this._removeWhite(param);
if (param<0x000000 || param>0xFFFFFF) {
param = this._constants.DEF_PAGEBACK;
}
return param;
};
FFlippingBookClass.prototype._validateParameters = function() {
this._bookWidth = this._validateNumber(this._bookWidth, 0, Infinity, this._constants.DEF_WIDTH);
this._bookHeight = this._validateNumber(this._bookHeight, 0, Infinity, this._constants.DEF_HEIGHT);
this.firstPage = this._validateNumber(this.firstPage, 0, Infinity, this._constants.DEF_FIRST_PAGE);
this.moveSpeed = this._validateNumber(this.moveSpeed, 0, Infinity, this._constants.DEF_MOVE_SPEED);
this.closeSpeed = this._validateNumber(this.closeSpeed, 0, Infinity, this._constants.DEF_CLOSE_SPEED);
this.gotoSpeed = this._validateNumber(this.gotoSpeed, 0, Infinity, this._constants.DEF_GOTO_SPEED);
this.autoFlip = this._validateNumber(this.autoFlip, 0, Infinity, this._constants.DEF_AUTOFLIP);
this._cache.sd = this.shadowsDepth=this._validateNumber(this.shadowsDepth, 0, Infinity, this._constants.DEF_SHADOWS_DEPTH);
this._cache.ssd = this.staticShadowsDepth=this._validateNumber(this.staticShadowsDepth, 0, Infinity, this._constants.DEF_SHADOWS_DEPTH);
this.pageBack = this._validateColor(this.pageBack);
this.alwaysOpened = this._validateBoolean(this.alwaysOpened, this._constants.DEF_ALWAYS_OPENED);
this.flipOnClick = this._validateBoolean(this.flipOnClick, this._constants.DEF_FLIP_ON_CLICK);
this.loadOnDemand = this._validateBoolean(this.loadOnDemand, this._constants.DEF_LOAD_ON_DEMAND);
this.cachePages = this._validateBoolean(this.cachePages, this._constants.DEF_CACHE_PAGES);
this.usePreloader = this._validateBoolean(this.usePreloader, this._constants.DEF_USE_PRELOADER);
this.scaleContent = this._validateBoolean(this.scaleContent, this._constants.DEF_SCALE_CONTENT);
this.preloaderType = this._removeWhite(this.preloaderType);
if (this.preloaderType == "") {
this.preloaderType = this._constants.DEF_PRELOADER_TYPE;
}
this.userPreloaderId = this._removeWhite(this.userPreloaderId);
this.cacheSize = this._validateNumber(this.cacheSize, 4, 100, this._constants.DEF_CACHE_SIZE);
this._cache.usePreloader = this.usePreloader;
this._cache.cachePages = this.cachePages;
this._cache.loadOnDemand = this.loadOnDemand;
this._cache.bgColor = this.pageBack;
};
FFlippingBookClass.prototype.gotoPage = function(i) {
if (this._view != undefined) {
this._view.gotoPage(i);
}
};
FFlippingBookClass.prototype.directGotoPage = function(i) {
var need = (i != this.leftPageNumber && i != this.rightPageNumber);
if (this._view != undefined && need) {
this._view.directGotoPage(i);
}
};
FFlippingBookClass.prototype.flipGotoPage = function(i) {
if (this._view != undefined) {
this._view.flipGotoPage(i);
}
};
function FFlippingBookView(bw, bh, autoFlip, flipOnClick, broker) {
this._const = new FFlippingBookConstants();
this._end = false;
this._broker = broker;
this._broker.registerObject(this._const.VIEW_OBJ_ID, this);
this._baseObj = this._broker.objects[this._const.MAIN_OBJ_ID];
this._cache = this._broker.objects[this._const.CACHE_OBJ_ID];
this._model = this._broker.objects[this._const.MODEL_OBJ_ID];
this._pageWidth = this._baseObj._bookWidth/2;
this._pageHeight = this._baseObj._bookHeight;
this._autoFlip = this._baseObj.autoFlip;
this._flipOnClick = this._baseObj.flipOnClick;
this._pageSpeed = this._baseObj.moveSpeed/this._const.SPEED_DIV;
this._closeSpeed = this._baseObj.closeSpeed/this._const.SPEED_DIV;
this._gotoSpeed = this._baseObj.gotoSpeed/this._const.SPEED_DIV;
this._minOffset = this._const.MIN_PAGE_OFFSET;
this._flipSound = this._cache._sound;
this._bookState = this._const.INIT_STATE;
this._depth = this._const.BOOK_DEPTH;
this.radIndex = 180/Math.PI;
this._transpPage = 0;
this.__ox = 0;
this.__oy = 0;
this.__oldX = 0;
this.__oldY = 0;
this.__p4Empty = false;
this.__shadowHeight = 2*Math.sqrt(this._pageHeight*this._pageHeight+this._pageWidth*this._pageWidth);
this.__pagesShadowHeight = 2*Math.sqrt(4*this._pageHeight*this._pageHeight+this._pageWidth*this._pageWidth);
this._radIndex = 180/Math.PI;
this.__gotoPageIndex = 0;
this.sd = this._baseObj.shadowsDepth;
this._drawBook();
this._baseObj.onMouseDown = this.__onMouseDown;
this._baseObj.onMouseUp = this.__onMouseUp;
this._baseObj.onEnterFrame = this.__onEnterFrame;
this._model.putPage();
}
FFlippingBookView.prototype.setSize = function(w, h) {
this._pageWidth = w/2;
this._pageHeight = h;
this.tmp01._x = this.__page01._x=-this._pageWidth;
this.tmp01._y = this.__page01._y=-this._pageHeight/2;
this.tmp02._x = this.__page02._x=0;
this.tmp02._y = this.__page02._y=-this._pageHeight/2;
this.tmp03._y = this.__page03._y=-this._pageHeight/2;
this.tmp04._y = this.__page04._y=-this._pageHeight/2;
this.__pagesShadowMask._x = -this._pageWidth;
this.__pagesShadowMask._y = -this._pageHeight/2;
this.__mask03._y = -this._pageHeight/2;
this.__mask12._y = -this._pageHeight/2;
this.__shMask03._y = -this._pageHeight/2;
this.__shMask04._y = -this._pageHeight/2;
this._drawShadow12();
this._drawShadow03();
this._drawShadow04();
};
FFlippingBookView.prototype._drawBook = function() {
this.__page04 = this.tmp04=this._baseObj.createEmptyMovieClip(this._const.PAGE_04_MC_NAME, this._depth++);
this.__shadow04 = this._baseObj.createEmptyMovieClip(this._const.SHADOW_04_MC_NAME, this._depth++);
this.__shMask04 = this._baseObj.createEmptyMovieClip(this._const.SH_MASK_04_MC_NAME, this._depth++);
this.__page01 = this.tmp01=this._baseObj.createEmptyMovieClip(this._const.PAGE_01_MC_NAME, this._depth++);
this.__page02 = this.tmp02=this._baseObj.createEmptyMovieClip(this._const.PAGE_02_MC_NAME, this._depth++);
this.__staticShadow = this._baseObj.createEmptyMovieClip(this._const.STATIC_SHADOW_MC_NAME, this._depth++);
this.__pagesShadow = this._baseObj.createEmptyMovieClip(this._const.PAGES_SH_MC_NAME, this._depth++);
this.__pagesShadowMask = this._baseObj.createEmptyMovieClip(this._const.PAGES_SHM_MC_NAME, this._depth++);
this.__mask12 = this._baseObj.createEmptyMovieClip(this._const.MASK_12_MC_NAME, this._depth++);
this.__page03 = this.tmp03=this._baseObj.createEmptyMovieClip(this._const.PAGE_03_MC_NAME, this._depth++);
this.__mask03 = this._baseObj.createEmptyMovieClip(this._const.MASK_03_MC_NAME, this._depth++);
this.__page03.setMask(this.__mask03);
this.__shadow03 = this._baseObj.createEmptyMovieClip(this._const.SHADOW_03_MC_NAME, this._depth++);
this.__shMask03 = this._baseObj.createEmptyMovieClip(this._const.SH_MASK_03_MC_NAME, this._depth++);
this.__page01._x = -this._pageWidth;
this.__page01._y = -this._pageHeight/2;
this.__page02._x = 0;
this.__page02._y = -this._pageHeight/2;
this.__page03._y = -this._pageHeight/2;
this.__page04._y = -this._pageHeight/2;
this.__pagesShadowMask._x = -this._pageWidth;
this.__pagesShadowMask._y = -this._pageHeight/2;
this.__mask03._y = -this._pageHeight/2;
this.__mask12._y = -this._pageHeight/2;
this.__shMask03._y = -this._pageHeight/2;
this.__shMask04._y = -this._pageHeight/2;
this._drawShadow12();
this._drawShadow03();
this._drawShadow04();
};
FFlippingBookView.prototype.__redrawBook = function() {
this.__drawShadow03();
this.__mask03._x = 0;
this.__drawShadow04();
this.__mask12._x = 0;
this._drawShadow12();
};
FFlippingBookView.prototype._drawShadow12 = function() {
this.__pagesShadow.clear();
this.__pagesShadow._x = 0;
this.__pagesShadow._y = 0;
var sw = this._const.SH12_SCALE*this._pageWidth;
var sh = this.__pagesShadowHeight;
var colors = [0x000000, 0x000000];
var ratios = [0, 255];
var alphas = [0, 25*this.sd];
var matrix = {matrixType:"box", x:-sw, y:-sh/2, w:sw, h:sh, r:0};
with (this.__pagesShadow) {
moveTo(-sw, -sh/2);
beginGradientFill("linear", colors, alphas, ratios, matrix);
lineTo(0, -sh/2);
lineTo(0, sh/2);
lineTo(-sw, sh/2);
lineTo(-sw, -sh/2);
endFill();
}
this.__pagesShadow._visible = false;
};
FFlippingBookView.prototype.__drawShadow12Mask = function() {
this.__pagesShadowMask.clear();
var ax = 0;
var ay = this._pageHeight;
var bx = 0;
var by = 0;
var cx = 2*this._pageWidth;
var cy = 0;
var dx = 2*this._pageWidth;
var dy = this._pageHeight;
if (this._transpPage == 1) {
ax += this._pageWidth;
bx += this._pageWidth;
} else if (this._transpPage == 2) {
cx -= this._pageWidth;
dx -= this._pageWidth;
}
with (this.__pagesShadowMask) {
moveTo(ax, ay);
beginFill(0x000000, 100);
lineTo(bx, by);
lineTo(cx, cy);
lineTo(dx, dy);
lineTo(ax, ay);
endFill();
}
this.__pagesShadow.setMask(this.__pagesShadowMask);
};
FFlippingBookView.prototype._drawShadow03 = function() {
this.__shadow03._x = 0;
this.__shadow03._y = 0;
this.__shadow03.clear();
var sw = this._const.SH3_SCALE*this._pageWidth;
var sh = this.__shadowHeight;
var colors = [0x000000, 0x000000, 0x000000, 0x000000];
var ratios = [0, 200, 242, 255];
var alphas = [0, 10*this.sd, 20*this.sd, 0];
var matrix = {matrixType:"box", x:-sw, y:-sh/2, w:sw, h:sh, r:0};
with (this.__shadow03) {
moveTo(-sw, -sh/2);
beginGradientFill("linear", colors, alphas, ratios, matrix);
lineTo(0, -sh/2);
lineTo(0, sh/2);
lineTo(-sw, sh/2);
lineTo(-sw, -sh/2);
endFill();
}
this.__shadow03._visible = false;
};
FFlippingBookView.prototype._drawShadow04 = function() {
this.__shadow04._x = 0;
this.__shadow04._y = 0;
this.__shadow04.clear();
var sw = 0.6*this._pageWidth;
var sh = this.__shadowHeight;
var colors = [0x000000, 0x000000];
var ratios = [0, 255];
var alphas = [0, 35*this.sd];
var matrix = {matrixType:"box", x:-sw, y:-sh/2, w:sw, h:sh, r:0};
with (this.__shadow04) {
moveTo(-sw, -sh/2);
beginGradientFill("linear", colors, alphas, ratios, matrix);
lineTo(0, -sh/2);
lineTo(0, sh/2);
lineTo(-sw, sh/2);
lineTo(-sw, -sh/2);
endFill();
}
this.__shadow04._visible = false;
};


FFlippingBookView.prototype.__isCorrectCorner = function(x, y) {
var c1 = this.__isCorner( Math.abs(x), Math.abs(y) );
var c2 = ( this.__oy * y > 0 ) && ( this.__ox * x > 0 );
return c1 && c2;
};

FFlippingBookView.prototype.__isCorner = function(x, y) {
if (x>(this._pageWidth-this._autoFlip)) {
if (x
if (y>(this._pageHeight/2-this._autoFlip)) {
if (y<(this._pageHeight/2)) {
return true;
}
}
}
}
return false;
};
FFlippingBookView.prototype.__onMouseUp = function() {
if (!this._visible || !this.enabled) {
return;
}
var targetObj = this._view;
if (targetObj._bookState == this._constants.FLIPPING_STATE) {
var isCorner = targetObj.__isCorner(Math.abs(targetObj._baseObj._xmouse), Math.abs(targetObj._baseObj._ymouse));
if (targetObj._flipOnClick || (!_flipOnClick && !isCorner)) {
targetObj._flipSound.start(0, 1);
}
var x = this._xmouse;
var y = this._ymouse;
var ox = targetObj.__ox;
if (isCorner) {
targetObj._bookState = this._constants.FLIPOVER_STATE;
targetObj._flipSound.start(0, 1);
} else {
targetObj._bookState = this._constants.FLIPBACK_STATE;
}
if ((ox<0 && x>0) || (ox>0 && x<0)) {
targetObj._bookState = this._constants.FLIPOVER_STATE;
}
}
};
FFlippingBookView.prototype.__onMouseDown = function() {
if (!this._visible || !this.enabled) {
return;
}
var targetObj = this._view;
var x = this._xmouse;
var y = this._ymouse;
if ((x>-targetObj._pageWidth) && (y>-targetObj._pageHeight/2) && (x
var corner = false;
if (targetObj._bookState == this._constants.AUTOFLIP_STATE) {
corner = true;
}
if (x<0) {
var vsrc = targetObj._baseObj.pagesSet[targetObj._model._userCurrentPage];
var cpn = targetObj._model._curPageNumbers[0];
var ph = targetObj._cache.__pagesHolders[targetObj._model._userPages[targetObj._model._curPageNumbers[0]]];
if (ph.media != undefined) {
ph = ph.media;
}
if (cpn != undefined) {
targetObj._baseObj.onClick(cpn, ph, corner);
}
} else if (x>0) {
var vsrc = targetObj._baseObj.pagesSet[targetObj._model._userCurrentPage];
var cpn = targetObj._model._curPageNumbers[1];
var ph = targetObj._cache.__pagesHolders[targetObj._model._userPages[targetObj._model._curPageNumbers[1]]];
if (ph.media != undefined) {
ph = ph.media;
}
if (cpn != undefined) {
targetObj._baseObj.onClick(cpn, ph, corner);
}
}
}
if (!targetObj._flipOnClick && !(targetObj._bookState == this._constants.AUTOFLIP_STATE)) {
return;
}
if (corner) {
if (targetObj._flipOnClick) {
targetObj._bookState = this._constants.FLIPPING_STATE;
} else {
targetObj._bookState = this._constants.FLIPPING_STATE;
}
}
if (x != 0 && (x>-targetObj._pageWidth) && (y>-targetObj._pageHeight/2) && (x
if (targetObj._bookState == this._constants.UNACTIVE_STATE) {
targetObj._bookState = this._constants.FLIPPING_STATE;
var ox = Math.sqrt(x*x+y*y);
var alpha = Math.asin(y/ox);
var y = Math.tan(alpha)*targetObj._pageWidth;
if (y>targetObj._pageHeight/2) {
y = targetObj._pageHeight/2;
}
if (y<-targetObj._pageHeight/2) {
y = -targetObj._pageHeight/2;
}
targetObj.__oy = y;
if (x<0) {
targetObj.__page04._x = -targetObj._pageWidth;
targetObj.__ox = -targetObj._pageWidth;
targetObj._model.goBack();
targetObj.onStartFlip(targetObj._model._curPageNumbers[0], true);
}
if (x>0) {
targetObj.__page04._x = 0;
targetObj.__ox = targetObj._pageWidth;
targetObj._model.goForward();
targetObj.onStartFlip(targetObj._model._curPageNumbers[1], false);
}
if (targetObj._bookState != this._constants.UNACTIVE_STATE) {
targetObj.__shadow03._visible = true;
targetObj.__shadow04._visible = true;
targetObj.__shadow03.setMask(targetObj.__shMask03);
targetObj.__shadow04.setMask(targetObj.__shMask04);
targetObj.__drawShadow12Mask();
}
targetObj.__oldX = targetObj.__ox;
targetObj.__oldY = targetObj.__oy;
}
}
};
FFlippingBookView.prototype.onStartFlip = function(p, isLeft) {
if (!this._baseObj.alwaysOpened) {
if (isLeft && this._baseObj.leftPageNumber == undefined) {
return;
} else if (!isLeft && this._baseObj.rightPageNumber == undefined) {
return;
}
} else {
if (isLeft && this._baseObj.leftPageNumber == 0) {
return;
}
if (!isLeft && this._baseObj.rightPageNumber == (this._baseObj.totalPages-1)) {
return;
}
}

var page_mc = this._baseObj.getPageLink(p);
page_mc.onStartFlip();
this._baseObj.onStartFlip(p);
};
FFlippingBookView.prototype.onSetPages = function(i, j) {
if (this._bookState == this._const.INIT_STATE) {
this._bookState = this._const.UNACTIVE_STATE;
} else if (this._bookState == this._const.UNACTIVE_STATE) {
this.__redrawBook();
} else if ((this._bookState == this._const.GOTOPAGE_STATE || this._bookState == this._const.FLIP_GOTOPAGE_STATE) && (i == 1)) {
this.__redrawBook();
this.__oldX = 0;
this.__oldY = 0;
if (this._bookState == this._const.GOTOPAGE_STATE) {
this._model.getNextGotoPage(this.__gotoPageIndex);
} else {
this._model.getFlipGotoPage(this.__gotoPageIndex, true);
}
if (this._bookState != this._const.UNACTIVE_STATE) {
this._flipSound.start(0, 1);
this.__pagesShadow._visible = true;
this.__shadow03._visible = true;
this.__shadow04._visible = true;
this.__shadow03.setMask(this.__shMask03);
this.__shadow04.setMask(this.__shMask04);
this.__drawShadow12Mask();
}
}
};
FFlippingBookView.prototype.__onEnterFrame = function() {
var targetObj = this._view;
var component = targetObj._baseObj;
component._initLibraryPages();
var leftPage = component.getPageLink(component.leftPageNumber);
var rightPage = component.getPageLink(component.rightPageNumber);
if (!leftPage.isExternal && !leftPage.onOpenCalled) {
leftPage.onOpen();
leftPage.onOpenCalled = true;
}
if (!rightPage.isExternal && !rightPage.onOpenCalled) {
rightPage.onOpen();
rightPage.onOpenCalled = true;
}
if (!this._visible || !this.enabled) {
return;
}
var x = this._xmouse;
var y = this._ymouse;
if (targetObj._bookState == targetObj._const.START_FLIP_CORNER_STATE) {
var coords = targetObj._getFlipCornerCoords();
x = coords.x;
y = coords.y;
targetObj._bookState = targetObj._const.FLIP_CORNER_STATE;
var ox = Math.sqrt(x*x+y*y);
var alpha = Math.asin(y/ox);
var y = Math.tan(alpha)*targetObj._pageWidth;
if (y>0) {
y = targetObj._pageHeight/2;
}
if (y<0) {
y = -targetObj._pageHeight/2;
}
targetObj.__oy = y;
y = -100;
if (x<0) {
targetObj.__page04._x = -targetObj._pageWidth;
targetObj.__ox = -targetObj._pageWidth;
targetObj._model.goBack();
}
if (x>0) {
targetObj.__page04._x = 0;
targetObj.__ox = targetObj._pageWidth;
targetObj._model.goForward();
}
if (targetObj._bookState != this._constants.UNACTIVE_STATE) {
targetObj.__pagesShadow._visible = true;
targetObj.__shadow03._visible = true;
targetObj.__shadow04._visible = true;
targetObj.__shadow03.setMask(targetObj.__shMask03);
targetObj.__shadow04.setMask(targetObj.__shMask04);
targetObj.__drawShadow12Mask();
}
targetObj.__oldX = targetObj.__ox;
targetObj.__oldY = targetObj.__oy;
} else if (targetObj._bookState == targetObj._const.AUTOFLIP_STATE) {

if (!targetObj.__isCorrectCorner(x, y ) ) {
targetObj._bookState = targetObj._const.FLIPBACK_STATE;
}
} else if (targetObj._bookState == targetObj._const.UNACTIVE_STATE && targetObj._autoFlip != 0) {
if (targetObj.__isCorner(Math.abs(x), Math.abs(y))) {
targetObj._bookState = targetObj._const.AUTOFLIP_STATE;
var ox = Math.sqrt(x*x+y*y);
var alpha = Math.asin(y/ox);
var y = Math.tan(alpha)*targetObj._pageWidth;
if (y>0) {
y = targetObj._pageHeight/2;
}
if (y<0) {
y = -targetObj._pageHeight/2;
}
targetObj.__oy = y;
y = this._ymouse;
if (x<0) {
targetObj.__page04._x = -targetObj._pageWidth;
targetObj.__ox = -targetObj._pageWidth;
targetObj._model.goBack();
targetObj.onStartFlip(targetObj._model._curPageNumbers[0], true);
}
if (x>0) {
targetObj.__page04._x = 0;
targetObj.__ox = targetObj._pageWidth;
targetObj._model.goForward();
targetObj.onStartFlip(targetObj._model._curPageNumbers[1], false);
}
if (targetObj._bookState != this._constants.UNACTIVE_STATE) {
targetObj.__pagesShadow._visible = true;
targetObj.__shadow03._visible = true;
targetObj.__shadow04._visible = true;
targetObj.__shadow03.setMask(targetObj.__shMask03);
targetObj.__shadow04.setMask(targetObj.__shMask04);
targetObj.__drawShadow12Mask();
}
targetObj.__oldX = targetObj.__ox;
targetObj.__oldY = targetObj.__oy;
}
}
if (targetObj._bookState == targetObj._const.FLIP_CORNER_STATE) {
var coords = targetObj._getFlipCornerCoords();
x = coords.x;
y = coords.y;
x = (targetObj.__oldX += (x-targetObj.__oldX)*targetObj._pageSpeed);
y = (targetObj.__oldY += (y-targetObj.__oldY)*targetObj._pageSpeed);
targetObj.__movePage(x, y);
if (Math.abs(x-coords.x)<1 && Math.abs(y-coords.y)) {
targetObj._bookState = targetObj._const.AUTOFLIP_STATE;
}
} else if (targetObj._bookState == targetObj._const.FLIPPING_STATE || targetObj._bookState == targetObj._const.AUTOFLIP_STATE) {
x = (targetObj.__oldX += (x-targetObj.__oldX)*targetObj._pageSpeed);
y = (targetObj.__oldY += (y-targetObj.__oldY)*targetObj._pageSpeed);
targetObj.__movePage(x, y);
} else if (targetObj._bookState == targetObj._const.FLIPOVER_STATE) {
x = (targetObj.__oldX += (-targetObj.__ox-targetObj.__oldX)*targetObj._closeSpeed);
y = (targetObj.__oldY += (targetObj.__oy-targetObj.__oldY)*targetObj._closeSpeed);
targetObj.__movePage(x, y);
if (x/-targetObj.__ox>targetObj._minOffset) {
targetObj._bookState = targetObj._const.UNACTIVE_STATE;
targetObj._cache.restorePages();
targetObj._model.putPage();
}
} else if (targetObj._bookState == targetObj._const.FLIPBACK_STATE) {
x = (targetObj.__oldX += (targetObj.__ox-targetObj.__oldX)*targetObj._closeSpeed);
y = (targetObj.__oldY += (targetObj.__oy-targetObj.__oldY)*targetObj._closeSpeed);
targetObj.__movePage(x, y);
if (x/targetObj.__ox>targetObj._minOffset) {
if (x>0) {
var sf_pn = targetObj._model._curPageNumbers[1];
var sf_pm = component.getPageLink(sf_pn);
sf_pm.onFlipBack();
component.onFlipBack(sf_pn);
} else {
var sf_pn = targetObj._model._curPageNumbers[0];
var sf_pm = component.getPageLink(sf_pn);
sf_pm.onFlipBack();
component.onFlipBack(sf_pn);
}
targetObj._bookState = targetObj._const.UNACTIVE_STATE;
targetObj._cache.restoreWorkPages();
targetObj.redrawBook();
}
} else if (targetObj._bookState == targetObj._const.GOTOPAGE_STATE || targetObj._bookState == targetObj._const.FLIP_GOTOPAGE_STATE) {
x = (targetObj.__oldX += (-targetObj.__ox-targetObj.__oldX)*targetObj._gotoSpeed);
y = (targetObj.__oldY += (targetObj.__oy-targetObj.__oldY)*targetObj._gotoSpeed);
targetObj.__movePage(x, y);
if (x/-targetObj.__ox>targetObj._minOffset) {
targetObj._cache.restorePages();
targetObj._model.putPage();
}
}
};
FFlippingBookView.prototype.__movePage = function(x, y) {
var pageH2 = this._pageHeight/2;
var pageW = this._pageWidth;
var r0 = Math.sqrt((pageH2+this.__oy)*(pageH2+this.__oy)+pageW*pageW);
var r1 = Math.sqrt((pageH2-this.__oy)*(pageH2-this.__oy)+pageW*pageW);
var rr0 = Math.sqrt((pageH2+y)*(pageH2+y)+x*x);
var rr1 = Math.sqrt((pageH2-y)*(pageH2-y)+x*x);
if (rr0>r0 || rr1>r1) {
if (y
var a = Math.asin((pageH2-y)/rr1);
y = (pageH2-Math.sin(a)*r1);
x = (x<0) ? -Math.cos(a)*r1 : Math.cos(a)*r1;
if (y>this.__oy) {
if ((this.__ox*x)>0) {
y = this.__oy;
x = this.__ox;
} else {
y = this.__oy;
x = -this.__ox;
}
}
} else {
var a = Math.asin((y+pageH2)/rr0);
y = Math.sin(a)*r0-pageH2;
x = (x<0) ? -Math.cos(a)*r0 : Math.cos(a)*r0;
if (y
if ((this.__ox*x)>0) {
y = this.__oy;
x = this.__ox;
} else {
y = this.__oy;
x = -this.__ox;
}
}
}
}
if ((this.__ox<0 && (x-this.__ox)<5) || (this.__ox>0 && (this.__ox-x)<5)) {
if (this.__ox<0) {
x = -pageW+5;
}
if (this.__ox>0) {
x = pageW-5;
}
}
var ddy = this.__oy-y;
var ddx = this.__ox-x;
var beta = Math.atan(ddy/ddx);
var alphaRad = 2*beta;
var alphaGrad = alphaRad*(180/Math.PI);
var sin_a = Math.sin(alphaRad);
var cos_a = Math.cos(alphaRad);
var px = x+(pageH2+this.__oy)*sin_a-(pageW-this.__ox)/2*cos_a;
var py = y-(pageH2+this.__oy)*cos_a-(pageW-this.__ox)/2*sin_a;
this.__page03._rotation = alphaGrad;
this.__page03._x = px;
this.__page03._y = py;
this.__drawMasks(beta, px, py, x, y);
this.__page03._visible = true;
this.__page04._visible = true;
};
FFlippingBookView.prototype.__drawMasks = function(beta, x, y, _mx, _my) {
var pageH = this._pageHeight;
var pageH2 = pageH/2;
var pageW = this._pageWidth;
var r = Math.sqrt((this.__ox-_mx)*(this.__ox-_mx)+(this.__oy-_my)*(this.__oy-_my));
var alpha = 2*beta;
var cos_a = Math.cos(alpha);
var sin_a = Math.sin(alpha);
var cos_b = Math.cos(beta);
var sin_b = Math.sin(beta);
var tan_a = sin_a/cos_a;
var tan_b = Math.tan(beta);
var bx = 0;
var by = 0;
var ax = 0;
var ay = pageH;
y = y+pageH2;
bx = x-y/tan_a;
ax = bx-pageH*tan_b;
if (beta == 0) {
if (this.__ox<0 && x<0) {
x = ax=bx=-pageW;
} else if (this.__ox>0 && x>0) {
x = ax=bx=pageW;
} else {
ax = bx=0;
}
}
var cx = (this.__ox>0) ? pageW : -pageW;
var cy = 0;
var dx = cx;
var dy = pageH;
var k = (this.__ox>0) ? 0 : 1;
var px = x+k*pageW*cos_a;
var py = y+k*pageW*sin_a;
var fx = px-pageH*sin_a;
var fy = py+pageH*cos_a;
var lx = cx;
var ly = (beta != 0) ? (bx-cx)/tan_b : -1;
var tmpx = 0;
var tmpy = 0;
var ccx = cx;
var ddx = dx;
cx = 0;
dx = 0;
if (this._transpPage04) {
ccx = ddx=cx;
}
if (ly<0 || ly>pageH) {
with (this.__mask03) {
clear();
moveTo(ax, ay);
beginFill(0xFFFF00, 100);
lineTo(bx, by);
lineTo(px, py);
lineTo(fx, fy);
lineTo(ax, ay);
endFill();
}
with (this.__mask12) {
clear();
moveTo(ax, ay);
beginFill(0x000000, 100);
lineTo(bx, by);
lineTo(cx, cy);
lineTo(dx, dy);
lineTo(ax, ay);
endFill();
}
with (this.__shMask03) {
clear();
moveTo(ax, ay);
beginFill(0xFFFF00, 100);
lineTo(bx, by);
lineTo(px, py);
lineTo(fx, fy);
lineTo(ax, ay);
endFill();
}
with (this.__shMask04) {
clear();
moveTo(ax, ay);
beginFill(0x000000, 100);
lineTo(bx, by);
lineTo(ccx, cy);
lineTo(ddx, dy);
lineTo(ax, ay);
endFill();
}
with (this.__pagesShadow) {
_rotation = beta*this.radIndex;
_xscale = (this.__ox>0) ? r/4 : -r/4;
ay = ay-pageH2;
by = by-pageH2;
var ab = Math.sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
_alpha = (2*pageW-r<50) ? 2*(2*pageW-r) : 100;
_x = bx-ab/2*sin_b;
_y = by+ab/2*cos_b;
_visible = true;
}
with (this.__shadow03) {
_rotation = this.__pagesShadow._rotation;
_xscale = this.__pagesShadow._xscale;
_alpha = this.__pagesShadow._alpha;
_x = this.__pagesShadow._x;
_y = this.__pagesShadow._y;
}
with (this.__shadow04) {
_rotation = this.__pagesShadow._rotation;
_xscale = -this.__pagesShadow._xscale;
_alpha = this.__pagesShadow._alpha;
_x = this.__pagesShadow._x;
_y = this.__pagesShadow._y;
}
} else {
if (bx>pageW || bx<-pageW) {
bx = ax;
by = ay;
tmpx = cx;
tmpy = cy;
cx = dx;
cy = dy;
dx = tmpx;
dy = tmpy;
px = fx;
py = fy;
}
with (this.__mask03) {
clear();
moveTo(lx, ly);
beginFill(0xFF0000, 100);
lineTo(px, py);
lineTo(bx, by);
lineTo(lx, ly);
endFill();
}
with (this.__mask12) {
clear();
moveTo(lx, ly);
beginFill(0x000000, 100);
lineTo(bx, by);
lineTo(cx, cy);
lineTo(dx, dy);
lineTo(lx, dy);
lineTo(lx, ly);
endFill();
}
with (this.__shMask03) {
clear();
moveTo(lx, ly);
beginFill(0xFF0000, 100);
lineTo(px, py);
lineTo(bx, by);
lineTo(lx, ly);
endFill();
}
with (this.__shMask04) {
clear();
moveTo(lx, ly);
beginFill(0xFF0000, 100);
lineTo(ccx, cy);
lineTo(bx, by);
lineTo(lx, ly);
endFill();
}
with (this.__pagesShadow) {
_rotation = beta*this.radIndex;
_xscale = (this.__ox>0) ? r/4 : -r/4;
ly = ly-pageH2;
by = by-pageH2;
var bl = Math.sqrt((lx-bx)*(lx-bx)+(ly-by)*(ly-by));
_alpha = (2*pageW-r<50) ? 2*(2*pageW-r) : 100;
_x = (by
_y = (by
_visible = true;
}
with (this.__shadow03) {
_rotation = this.__pagesShadow._rotation;
_xscale = this.__pagesShadow._xscale;
_alpha = this.__pagesShadow._alpha;
_x = this.__pagesShadow._x;
_y = this.__pagesShadow._y;
}
with (this.__shadow04) {
_rotation = this.__pagesShadow._rotation;
_xscale = -this.__pagesShadow._xscale;
_alpha = this.__pagesShadow._alpha;
_x = this.__pagesShadow._x;
_y = this.__pagesShadow._y;
}
}
this.__page03.setMask(this.__mask03);
this.__shadow03.setMask(this.__shMask03);
this.__shadow04.setMask(this.__shMask04);
(this.__ox>0) ? this.__page02.setMask(this.__mask12) : this.__page01.setMask(this.__mask12);
};
FFlippingBookView.prototype.flipCorner = function(position) {
if (this._bookState != this._const.UNACTIVE_STATE) {
return;
}
this._flipCornerPosition = position;
this._bookState = this._const.START_FLIP_CORNER_STATE;
this._flipSound.start(0, 1);
};
FFlippingBookView.prototype._getFlipCornerCoords = function() {
var d = this._autoFlip;
var fx = 0;
var fy = 0;
switch (this._flipCornerPosition) {
case "top-left" :
fx = -this._pageWidth+this._autoFlip;
fy = -this._pageHeight/2+this._autoFlip/2;
break;
case "top-right" :
fx = this._pageWidth-this._autoFlip;
fy = -this._pageHeight/2+this._autoFlip/2;
break;
case "bottom-left" :
fx = -this._pageWidth+this._autoFlip;
fy = this._pageHeight/2-this._autoFlip/2;
break;
case "bottom-right" :
fx = this._pageWidth-this._autoFlip;
fy = this._pageHeight/2-this._autoFlip/2;
break;
}
return {x:fx, y:fy};
};
FFlippingBookView.prototype.directGotoPage = function(n) {
if (this._bookState != this._const.UNACTIVE_STATE) {
return;
}
var cp = this._model._currentPage;
this._model._currentPage = this._model._realPageNumber(n);
this._cache.restoreDirectGotoPages();
this._model.__direction = -1;
var direct_dir = 0;
if (cp
direct_dir = 1;
}
this._model.putPage(true, direct_dir);
this.__page01.setMask(null);
this.__page02.setMask(null);
this._baseObj.onEndGoto();
};
FFlippingBookView.prototype.flipGotoPage = function(n) {
if (this._bookState != this._const.UNACTIVE_STATE) {
return;
}
this._bookState = this._const.FLIP_GOTOPAGE_STATE;
this.__gotoPageIndex = this._model._realPageNumber(n);
this._model._last_current_page = this._model._currentPage;
if (this._model._currentPage>this.__gotoPageIndex) {
this.__page04._x = -this._pageWidth;
this.__ox = -this._pageWidth;
this.__oy = -this._pageHeight/2;
}
if (this._model._currentPage
this.__page04._x = 0;
this.__ox = this._pageWidth;
this.__oy = -this._pageHeight/2;
}
this.__oldX = 0;
this.__oldY = 0;
this._model.getFlipGotoPage(this.__gotoPageIndex, false);
if (this._bookState != this._const.UNACTIVE_STATE) {
this._flipSound.start(0, 1);
this.__pagesShadow._visible = true;
this.__shadow03._visible = true;
this.__shadow04._visible = true;
this.__shadow03.setMask(this.__shMask03);
this.__shadow04.setMask(this.__shMask04);
this.__drawShadow12Mask();
}
};
FFlippingBookView.prototype.gotoPage = function(n) {
if (this._bookState != this._const.UNACTIVE_STATE) {
return;
}
this._bookState = this._const.GOTOPAGE_STATE;
this.__gotoPageIndex = this._model._realPageNumber(n);
if (this._model._currentPage>this.__gotoPageIndex) {
this.__page04._x = -this._pageWidth;
this.__ox = -this._pageWidth;
this.__oy = -this._pageHeight/2;
}
if (this._model._currentPage
this.__page04._x = 0;
this.__ox = this._pageWidth;
this.__oy = -this._pageHeight/2;
}
this.__oldX = 0;
this.__oldY = 0;
this._model.getNextGotoPage(this.__gotoPageIndex);
if (this._bookState != this._const.UNACTIVE_STATE) {
this._flipSound.start(0, 1);
this.__pagesShadow._visible = true;
this.__shadow03._visible = true;
this.__shadow04._visible = true;
this.__shadow03.setMask(this.__shMask03);
this.__shadow04.setMask(this.__shMask04);
this.__drawShadow12Mask();
}
};
Object.registerClass("FFlippingBookSymbol", FFlippingBookClass);
#endinitclip

Script for loader bar
function setProgress(pt) {
bar_mc._xscale = pt;
}
setProgress(0);

function setProgress(pt) {
if (pt<=50) {
seg2_mc.mask._rotation = 0;
seg1_mc.mask._rotation = 180*(pt/50);
} else {
seg1_mc.mask._rotation = 180;
seg2_mc.mask._rotation = 180*((pt-50)/50);
}
}
setProgress(0);

function setbar(PC) {
if(PC<=50) {
s2.mask._rotation = 0;
s1.mask._rotation = 180*(PC/50);
} else {
s1.mask._rotation = 180;
s2.mask._rotation = 180*((PC-50)/50);
}
}
Script to print page
print_btn.onPress = function() {
printPage(page_number_txt.text);
};
function printPage(pageNumber) {
var page_mc = myBook.getPageLink(pageNumber);
var parent = page_mc._parent._parent;
var visible = parent._visible;
var my_pj:PrintJob = new PrintJob();
if (my_pj.start()) {
var pagesToPrint:Number = 0;
if (!visible) {
parent._visible = true;
}
if (page_mc && my_pj.addPage(page_mc)) {
pagesToPrint++;
}
if (pagesToPrint>0) {
my_pj.send();
}
if (!visible) {
parent._visible = false;
}
}
delete my_pj;
}

Script for page to flip to a particular page
function onInit(){
number_txt.text = pageNumber;
}

myBook.onPutPage = function() {
this.flipOnClickProp = false;
};
myBook.onStartFlip = function(pageNumber) {
this.flipOnClickProp = true;
};
myBook.onFlipBack = function() {
this.flipOnClickProp = false;
};

var lo = new Object();

lo.change = function (evt_obj:Object) {
var dest_page_number = evt_obj.target.selectedItem.data;
book.flipGotoPage(dest_page_number);
}
combo_mc.addEventListener("change", lo);

function onInit(){
number_txt.text = pageNumber;
lo.book = book;
}

Script for wide page
wideLeftPageNumber = 1;
wideRightPageNumber = 2;

myBook.onPageLoad = function(pageURL, pageNumber) {
if (pageNumber == wideLeftPageNumber || pageNumber == wideRightPageNumber && !_root.onEnterFrame) {
_root.onEnterFrame = checkWidePages;
}
};

function checkWidePages() {
var leftWidePage = myBook.getPageLink(wideLeftPageNumber);
var rightWidePage = myBook.getPageLink(wideRightPageNumber);

if (leftWidePage.loaded && rightWidePage.loaded) {
leftWidePage.gotoAndPlay(2);
rightWidePage._x = -rightWidePage.width;
rightWidePage.gotoAndPlay(2);
delete this.onEnterFrame;
}
}

Script for zooming
import mx.containers.Window;
// Popup size
popup_width = 527;
popup_height = 400;
// Zooming settings
zooming = false;
zoom_panel_mc.zoom_btn.onPress = startZoomingMode;
myBook.onClick = bookClick;
function startZoomingMode() {
myBook.flipOnClickProp = false;
myBook.autoFlipProp = 0;
showZoomPointer();
zooming = true;
}
function bookClick(pageNumber, page_mc, isCornerClick) {
if (!zooming) {
return;
}
var page_url = page_mc.URL;
if (page_url != undefined) {
open_popup(page_url, pageNumber);
} else {
zooming = false;
myBook.flipOnClickProp = true;
myBook.autoFlipProp = 50;
hideZoomPointer();
}
}
function open_popup(page_url, pageNumber) {
if (zoom_win != undefined) {
return;
}
hideZoomPointer();
zoom_win = mx.managers.PopUpManager.createPopUp(_root, Window, true, {title:"Page Number: " + pageNumber, closeButton:true});
zoom_win.createObject("ScrollPane", "zoom_pane", 0, {contentPath:page_url, _x:3, _y:31});
zoom_win.setSize(popup_width, popup_height);
zoom_win.zoom_pane.setSize(popup_width-6, popup_height-31);
listenerObject = new Object();
listenerObject.click = closeWindow;
zoom_win.addEventListener("click", listenerObject);
zoom_win._x = Stage.width/2-popup_width/2;
zoom_win._y = Stage.height/2-popup_height/2;
}
function closeWindow(eventObject:Object) {
zoom_win.deletePopUp();
zooming = false;
delete zoom_win;
myBook.flipOnClickProp = true;
myBook.autoFlipProp = 50;
}
function showZoomPointer() {
Mouse.hide();
attachMovie("ZoomIcon", "zoom_icon_mc", 0);
zoom_icon_mc.onEnterFrame = function() {
this._x = _xmouse;
this._y = _ymouse;
};
}
function hideZoomPointer() {
Mouse.show();
delete zoom_icon_mc.onEnterFrame;
zoom_icon_mc.removeMovieClip();
}

Script for spiral animation
spiral._rotation = (15*(mcnt-1))%360; //mcnt is a global counter!!! of pageflip main movie!
//trace("reset spiral "+(mcnt-1));

onEnterFrame = function () {
spiral._rotation = (15*mcnt)%360;
//trace(mcnt);
}

Script for flip area
afa0._xscale = afa0._yscale = _level0.afa;
afa1._xscale = afa1._yscale = _level0.afa;
click._width = _level0.clickarea;
txt._x = 8+_level0.clickarea;