Advertisement
Guest User

Untitled

a guest
Dec 31st, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * VCam AS2 v1.0
  3.  *
  4.  * VCam based on original code by Sham Bhangal and Dave Dixon
  5.  *
  6.  * Dynamic Registration AS2 work by Darron Schall (www.darronschall.com)
  7.  * and AS1 work by Robert Penner (www.robertpenner.com)
  8.  *
  9.  * Special Thanks to Josh Steele and Jeff Brenner
  10.  *
  11.  * @author Bryan Heisey
  12.  * @version 1.0
  13.  * @created 1-April-2008
  14.  *
  15.   * Requirements: Flash 8+ & Actionscript 2
  16.  */
  17.  
  18. import flash.display.BitmapData;
  19.  
  20. _visible = false;
  21.  
  22. addProperty("_x2",get_x2,set_x2);
  23. addProperty("_y2",get_y2,set_y2);
  24. addProperty("_xscale2",get_xscale2,set_xscale2);
  25. addProperty("_yscale2",get_yscale2,set_yscale2);
  26. addProperty("_rotation2",get_rotation2,set_rotation2);
  27.  
  28. ////////////////////////////////////////////////////////////////////////////
  29. // Get stage width and height //////////////////////////////////////////////
  30.  
  31. var oldScaleMode:String = stage.scaleMode;
  32. stage.scaleMode = "exactFit";
  33.  
  34. var sW:Number = Stage.width;
  35. var sH:Number = Stage.height;
  36.  
  37. stage.scaleMode = oldScaleMode;
  38.  
  39. ////////////////////////////////////////////////////////////////////////////
  40. // Get Vcam width and height ///////////////////////////////////////////////
  41.  
  42. var bounds_obj:Object = this.getBounds(this);
  43.  
  44. var camH:Number = Math.abs(bounds_obj.yMax-bounds_obj.yMin);
  45. var camW:Number = Math.abs(bounds_obj.xMax-bounds_obj.xMin);
  46.  
  47. ////////////////////////////////////////////////////////////////////////////
  48. // Creat Point for dynamic registration point //////////////////////////////
  49.  
  50. var rp = {x:this._x, y:this._y};
  51.  
  52. onEnterFrame = function ():Void {
  53.     camControl();
  54. };
  55.  
  56. ////////////////////////////////////////////////////////////////////////////
  57. ////////////////////////////////////////////////////////////////////////////
  58.  
  59. function camControl():Void {
  60.  
  61.     ////////////////////////////////////////////////////////////////////////////
  62.     // Move the registration point to the vCams current position ///////////////
  63.  
  64.     rp.x = _x;
  65.     rp.y = _y;
  66.  
  67.     ////////////////////////////////////////////////////////////////////////////
  68.     // Gets the current scale of the vCam //////////////////////////////////////
  69.  
  70.     var h:Number = camH*(_yscale*.01);
  71.     var w:Number = camW*(_xscale*.01);
  72.  
  73.     ////////////////////////////////////////////////////////////////////////////
  74.     // Gets the stage to vCam scale ratio //////////////////////////////////////
  75.  
  76.     var _scaleY:Number = sH/h;
  77.     var _scaleX:Number = sW/w;
  78.  
  79.     ////////////////////////////////////////////////////////////////////////////
  80.     // Positions the parent ////////////////////////////////////////////////////
  81.  
  82.     _x2 = (w/2)*_scaleX;
  83.     _y2 = (h/2)*_scaleY;
  84.  
  85.     _xscale2 = _scaleX*100;
  86.     _yscale2 = _scaleY*100;
  87.  
  88.     _rotation2 = -_rotation;
  89.  
  90.     ////////////////////////////////////////////////////////////////////////////
  91.     // Apply vCam filters to bitmap ////////////////////////////////////////////
  92.  
  93.     _parent.filters = this.filters;
  94.     _parent.transform.colorTransform = this.transform.colorTransform;
  95.  
  96. }
  97.  
  98. this.onUnload = reset;
  99.  
  100. function reset():Void {
  101.  
  102.     ////////////////////////////////////////////////////////////////////////////
  103.     // Resets parent properties ////////////////////////////////////////////////
  104.  
  105.     _parent._xscale = 100;
  106.     _parent._yscale = 100;
  107.     _parent._x = 0;
  108.     _parent._y = 0;
  109.     _parent._rotation = 0;
  110.     _parent._visible = true;
  111.  
  112. }
  113.  
  114. function set_x2(value:Number):Void {
  115.     var a = {x:rp.x, y:rp.y};
  116.     _parent.localToGlobal(a);
  117.     _parent._x += value-a.x;
  118. }
  119. function get_x2():Number {
  120.     var a = {x:rp.x, y:rp.y};
  121.     _parent.localToGlobal(a);
  122.     return a.x;
  123. }
  124.  
  125. function set_y2(value:Number):Void {
  126.     var a = {x:rp.x, y:rp.y};
  127.     _parent.localToGlobal(a);
  128.     _parent._y += value-a.y;
  129. }
  130. function get_y2():Number {
  131.     var a = {x:rp.x, y:rp.y};
  132.     _parent.localToGlobal(a);
  133.     return a.y;
  134. }
  135.  
  136. function get_xscale2():Number {
  137.     return _parent._xscale;
  138. }
  139. function set_xscale2(value:Number):Void {
  140.     setProperty2("_xscale",value);
  141. }
  142.  
  143. function get_yscale2():Number {
  144.     return _parent._yscale;
  145. }
  146.  
  147. function set_yscale2(value:Number):Void {
  148.     setProperty2("_yscale",value);
  149. }
  150.  
  151. function get_rotation2():Number {
  152.     return parent.rotation;
  153. }
  154. function set_rotation2(value:Number):Void {
  155.     setProperty2("_rotation",value);
  156. }
  157.  
  158. function setProperty2(prop:String, n:Number):Void {
  159.     var a = {x:rp.x, y:rp.y};
  160.     _parent.localToGlobal(a);
  161.  
  162.     _parent[prop] = n;
  163.  
  164.     var b = {x:rp.x, y:rp.y};
  165.     _parent.localToGlobal(b);
  166.  
  167.     _parent._x -= b.x-a.x;
  168.     _parent._y -= b.y-a.y;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement