Created
August 29, 2012 03:36
-
-
Save cccaldas/3506555 to your computer and use it in GitHub Desktop.
FlippingBook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scripts { | |
import caurina.transitions.Tweener; | |
import com.geleca.as3.util.FunctionUtil; | |
import flash.display.*; | |
import flash.events.*; | |
import flash.net.*; | |
import flash.system.Security; | |
import mx.core.UIComponent; | |
public class FlippingBook extends UIComponent { | |
public static const READY :String = "ready"; | |
public static const RESIZE :String = "resize"; | |
private var _width :Number; | |
private var _height :Number; | |
private var _urlXML :String; | |
[Embed(source="../assets/flip/book.swf")] | |
private var _book_asset :Class; | |
private var _book :Sprite; | |
private var _loader :Loader; | |
private var _shape :Shape; | |
private var _cache :Bitmap; | |
private var _cache_data :BitmapData; | |
private var _connection :LocalConnection; | |
private var _lc_token :String; | |
public function FlippingBook(width:Number, height:Number, urlXML:String) { | |
super(); | |
_width = width; | |
_height = height; | |
_urlXML = urlXML; | |
_shape = new Shape(); | |
_shape.graphics.beginFill(0x000000, 0); | |
_shape.graphics.drawRect(0, 0, _width, _height); | |
_shape.graphics.endFill(); | |
addChild(_shape); | |
_book = new _book_asset(); | |
_book.x = 932; | |
_book.y = 614; | |
addChild(_book); | |
_cache = new Bitmap(_cache_data); | |
_cache.x = _book.x; | |
_cache.y = _book.y; | |
_cache_data = new BitmapData(_width, _height, false); | |
_loader = Loader(_book.getChildAt(0)); | |
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete); | |
_connection = new LocalConnection(); | |
_connection.addEventListener(StatusEvent.STATUS, lc_status); | |
function lc_status(e:StatusEvent):void { | |
//trace("FlippingBook::lc_status()", e); | |
} | |
} | |
private function loader_complete(e:Event):void { | |
//trace("FlippingBook::loader_complete()", this.loaderInfo.bytesLoaded / this.loaderInfo.bytesTotal); | |
FunctionUtil.functionDelay(function():void { | |
_lc_token = "token_" + String(Math.random() * 9999); | |
//trace("token avm3: " + _lc_token); | |
_connection.send("avm2", "token", _lc_token); | |
FunctionUtil.functionDelay(function():void { | |
_connection.send(_lc_token, "load", _urlXML); | |
dispatchEvent(new Event(FlippingBook.READY)); | |
}, .1); | |
//_connection.send("avm2", "load", _urlXML); | |
}, .3); | |
} | |
public function flipForward():void { | |
_connection.send(_lc_token, "flipForward"); | |
} | |
public function flipBack():void { | |
_connection.send(_lc_token, "flipBack"); | |
} | |
public function gotoPage(page:uint):void { | |
_connection.send(_lc_token, "gotoPage", page); | |
} | |
public function zoom(length:Number):void { | |
Tweener.removeTweens(this); | |
//if(Tweener.isTweening(_container)) | |
//return; | |
if(length > 1) | |
length = 1; | |
if(length < .2) | |
length = .2; | |
//_container.filters = [new BlurFilter()]; | |
Tweener.addTween(this, {time:.3, scaleX:length, scaleY:length, onUpdate:onUpdate, onComplete:onComplete}); | |
function onUpdate():void { | |
this.dispatchEvent(new Event(FlippingBook.RESIZE)) | |
} | |
function onComplete():void { | |
} | |
} | |
public function zoomIn():void { | |
//trace("Main::zoomIn()"); | |
zoom(1); | |
//enableMove(); | |
} | |
public function zoomOut():void { | |
//trace("Main::zoomOut()"); | |
zoom(.4); | |
//disableMove(); | |
} | |
public function enable():void { | |
_connection.send(_lc_token, "unlock"); | |
//_book.visible = true; | |
//addChild(_book); | |
//removeChild(_cache); | |
} | |
public function disable():void { | |
_connection.send(_lc_token, "lock"); | |
//_cache_data.draw(this); | |
//_cache = new Bitmap(_cache_data); | |
//_book.visible = false; | |
//removeChild(_book); | |
//addChild(_cache); | |
} | |
override public function get width() :Number { return _width * this.scaleX; } | |
override public function get height() :Number { return _height * this.scaleX; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment