Guest User

Untitled

a guest
Dec 11th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. package scripts {
  2. import caurina.transitions.Tweener;
  3.  
  4. import com.geleca.as3.util.FunctionUtil;
  5.  
  6. import flash.display.*;
  7. import flash.events.*;
  8. import flash.net.*;
  9. import flash.system.Security;
  10.  
  11. import mx.core.UIComponent;
  12.  
  13. public class FlippingBook extends UIComponent {
  14.  
  15. public static const READY :String = "ready";
  16. public static const RESIZE :String = "resize";
  17.  
  18. private var _width :Number;
  19. private var _height :Number;
  20. private var _urlXML :String;
  21.  
  22. [Embed(source="../assets/flip/book.swf")]
  23. private var _book_asset :Class;
  24. private var _book :Sprite;
  25. private var _loader :Loader;
  26. private var _shape :Shape;
  27.  
  28. private var _cache :Bitmap;
  29. private var _cache_data :BitmapData;
  30.  
  31. private var _connection :LocalConnection;
  32.  
  33. private var _lc_token :String;
  34.  
  35. public function FlippingBook(width:Number, height:Number, urlXML:String) {
  36. super();
  37.  
  38. _width = width;
  39. _height = height;
  40. _urlXML = urlXML;
  41.  
  42. _shape = new Shape();
  43. _shape.graphics.beginFill(0x000000, 0);
  44. _shape.graphics.drawRect(0, 0, _width, _height);
  45. _shape.graphics.endFill();
  46. addChild(_shape);
  47.  
  48. _book = new _book_asset();
  49. _book.x = 932;
  50. _book.y = 614;
  51. addChild(_book);
  52.  
  53. _cache = new Bitmap(_cache_data);
  54. _cache.x = _book.x;
  55. _cache.y = _book.y;
  56.  
  57. _cache_data = new BitmapData(_width, _height, false);
  58.  
  59. _loader = Loader(_book.getChildAt(0));
  60. _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
  61.  
  62. _connection = new LocalConnection();
  63. _connection.addEventListener(StatusEvent.STATUS, lc_status);
  64.  
  65. function lc_status(e:StatusEvent):void {
  66. //trace("FlippingBook::lc_status()", e);
  67. }
  68. }
  69.  
  70. private function loader_complete(e:Event):void {
  71. //trace("FlippingBook::loader_complete()", this.loaderInfo.bytesLoaded / this.loaderInfo.bytesTotal);
  72.  
  73. FunctionUtil.functionDelay(function():void {
  74.  
  75. _lc_token = "token_" + String(Math.random() * 9999);
  76. //trace("token avm3: " + _lc_token);
  77. _connection.send("avm2", "token", _lc_token);
  78.  
  79. FunctionUtil.functionDelay(function():void {
  80. _connection.send(_lc_token, "load", _urlXML);
  81. dispatchEvent(new Event(FlippingBook.READY));
  82. }, .1);
  83.  
  84. //_connection.send("avm2", "load", _urlXML);
  85.  
  86. }, .3);
  87.  
  88.  
  89. }
  90.  
  91. public function flipForward():void {
  92. _connection.send(_lc_token, "flipForward");
  93. }
  94.  
  95. public function flipBack():void {
  96. _connection.send(_lc_token, "flipBack");
  97. }
  98.  
  99. public function gotoPage(page:uint):void {
  100. _connection.send(_lc_token, "gotoPage", page);
  101. }
  102.  
  103. public function zoom(length:Number):void {
  104. Tweener.removeTweens(this);
  105. //if(Tweener.isTweening(_container))
  106. //return;
  107.  
  108. if(length > 1)
  109. length = 1;
  110.  
  111. if(length < .2)
  112. length = .2;
  113.  
  114. //_container.filters = [new BlurFilter()];
  115. Tweener.addTween(this, {time:.3, scaleX:length, scaleY:length, onUpdate:onUpdate, onComplete:onComplete});
  116.  
  117. function onUpdate():void {
  118. this.dispatchEvent(new Event(FlippingBook.RESIZE))
  119. }
  120.  
  121. function onComplete():void {
  122.  
  123. }
  124. }
  125.  
  126. public function zoomIn():void {
  127. //trace("Main::zoomIn()");
  128. zoom(1);
  129. //enableMove();
  130. }
  131.  
  132. public function zoomOut():void {
  133. //trace("Main::zoomOut()");
  134. zoom(.4);
  135. //disableMove();
  136. }
  137.  
  138. public function enable():void {
  139. _connection.send(_lc_token, "unlock");
  140. //_book.visible = true;
  141. //addChild(_book);
  142. //removeChild(_cache);
  143. }
  144.  
  145. public function disable():void {
  146. _connection.send(_lc_token, "lock");
  147. //_cache_data.draw(this);
  148. //_cache = new Bitmap(_cache_data);
  149. //_book.visible = false;
  150. //removeChild(_book);
  151. //addChild(_cache);
  152. }
  153.  
  154. override public function get width() :Number { return _width * this.scaleX; }
  155. override public function get height() :Number { return _height * this.scaleX; }
  156.  
  157. }
  158.  
  159. }
Add Comment
Please, Sign In to add comment