Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.Sprite;
  4.     import flash.events.Event;
  5.     import flash.geom.Rectangle;
  6.    
  7.     public class Movie14 extends Sprite
  8.     {
  9.         public var next_frame:int = 1;
  10.         public var total_frames:int = 3;
  11.         public var current_frame:int = -1;
  12.         public var is_playing:Boolean = true;
  13.         public var frame_labels:Array = ["Scene 1"];
  14.         public var frame_numbers:Array = [1];
  15.         public function Movie14()
  16.         {
  17.             _elements.root = this;
  18.             _elements.paint7 = new CPaint7;
  19.             addChild (_elements.paint7);
  20.             addEventListener ("enterFrame", onEnterFrame);
  21.         }
  22.         public function restart():void
  23.         {
  24.             for (var i:int=0; i<_elements; i++){
  25.                 var e:* = _elements[i];
  26.                 if (e.hasOwnProperty("reset")) e.reset();}
  27.             gotoAndPlay (0);
  28.         }
  29.         public function play ():void { is_playing = true;}
  30.         public function stop ():void { is_playing = false; next_frame = current_frame;}
  31.         public function start ():void { is_playing = true; next_frame = 0;}
  32.         public function gotoAndPlay (frame:*):void { is_playing = true; next_frame = getFrameNumber (frame);}
  33.         public function gotoAndStop (frame:*):void { is_playing = false; next_frame = getFrameNumber (frame);}
  34.         public function getFrameNumber (frame:*):int
  35.         {
  36.             var i:int = frame_labels.indexOf (frame);
  37.             if (i == -1) return frame;
  38.             return frame_numbers[i];
  39.         }
  40.         public function placeImage (image:*, frame:int):void
  41.         {
  42.             var i:int = image.frames.indexOf(frame);
  43.             while (i > -1 && i < image.frames.length && image.frames[i] == frame){
  44.                 var j:int = image.indices[i++];
  45.                 var t:int = image.places[j++];
  46.                 if (t & 1) image.x = image.places[j++];
  47.                 if (t & 2) image.y = image.places[j++];
  48.                 if (t & 4) image.scaleX = image.places[j++] / 100;
  49.                 if (t & 8) image.scaleY = image.places[j++] / 100;
  50.                 if (t & 16) image.alpha = image.places[j++] / 100;
  51.                 if (t & 32) image.rotation = image.places[j++];
  52.                 if (t & 64) image.visible = image.places[j++];
  53.                 if (t & 128) image.play();}
  54.         }
  55.         public function onEnterFrame (_e:Event):void
  56.         {
  57.             for (var _i:int=poll_objects.length-1; _i>=0; _i--){
  58.                 var _obj:* = poll_objects[_i];
  59.                 _obj.poll (0.05);}
  60.            
  61.             var new_frame:Boolean = false;
  62.             if (current_frame != next_frame){
  63.                 current_frame = next_frame;
  64.                 new_frame = true;}
  65.             if (is_playing){
  66.                 if (++next_frame >= 3) next_frame = 0;}
  67.             if (new_frame){
  68.                 placeImage (_elements.paint7, current_frame);
  69.                 if (current_frame == 2) onFrame2 (_e);
  70.             }
  71.         }
  72.         public function onFrame2 (_e:Event):void
  73.         {
  74.             stop ();
  75.         }
  76.     }
  77. }
  78.  
  79. import flash.display.Sprite;
  80. import flash.events.Event;
  81. import flash.geom.Rectangle;
  82.  
  83. var _elements:Object = new Object;
  84. var poll_objects:Array = new Array;
  85.  
  86. class CPaint7 extends Sprite
  87. {
  88.     public var velocity_x:Number = 40;
  89.     public var velocity_y:Number = 40;
  90.     public var acceleration_x:Number = 0.0;
  91.     public var acceleration_y:Number = 0.0;
  92.     public var scale_rate_x:Number = 0.0;
  93.     public var scale_rate_y:Number = 0.0;
  94.     public var alpha_rate:Number = 0.0;
  95.     public var friction_x:Number = 0.0;
  96.     public var friction_y:Number = 0.0;
  97.     public var angular_velocity:Number = 0.0;
  98.     public var angular_acceleration:Number = 0.0;
  99.     public var angular_friction:Number = 0.0;
  100.    
  101.     [Embed(source="paint7.swf")]
  102.     public var Paint7:Class;
  103.    
  104.     public var clone_parent:* = null;
  105.     public var clone_array:Array = new Array;
  106.     public var frames:Array = [0];
  107.     public var indices:Array = [0];
  108.     public var places:Array = [127,160,240,100,100,100,0,true];
  109.    
  110.     public function CPaint7()
  111.     {
  112.         name = "Paint 7";
  113.         x = 160;
  114.         y = 240;
  115.         addChild (new Paint7);
  116.         addEventListener ("enterFrame", onEnterFrame);
  117.     }
  118.     function physics (velocity:Number, acceleration:Number, maximum:Number, friction:Number):Number
  119.     {
  120.         if (acceleration != 0.0) velocity += acceleration * 0.05;
  121.        
  122.         if (friction > 0.0){
  123.             if (velocity > 0.0){
  124.                 velocity -= friction * 0.05;
  125.                 if (velocity < 0.0) velocity = 0.0;}
  126.             else if (velocity < 0.0){
  127.                 velocity += friction * 0.05;
  128.                 if (velocity > 0.0) velocity = 0.0;}}
  129.        
  130.         if (maximum > 0.0){
  131.             if (velocity > maximum) velocity = maximum;
  132.             if (velocity < -maximum) velocity = -maximum;}
  133.        
  134.         return velocity;
  135.     }
  136.     public function reset():void
  137.     {
  138.         if (hasOwnProperty ("places")) _elements.root.placeImage (this, 0);
  139.     }
  140.     public function clone():*
  141.     {
  142.         var _c:CPaint7 = new CPaint7;
  143.         parent.addChildAt (_c, parent.getChildIndex (this) + 1);
  144.         clone_array.push (_c);
  145.         _c.clone_parent = this;
  146.         return _c;
  147.     }
  148.     public function onEnterFrame (_e:Event):void
  149.     {
  150.         if (velocity_x != 0) x += velocity_x * 0.05;
  151.         if (velocity_y != 0) y += velocity_y * 0.05;
  152.         if (angular_velocity != 0) rotation += angular_velocity * 0.05;
  153.         velocity_x = physics (velocity_x, acceleration_x, 0.0, friction_x);
  154.         velocity_y = physics (velocity_y, acceleration_y, 0.0, friction_y);
  155.         angular_velocity = physics (angular_velocity, angular_acceleration, 0.0, angular_friction);
  156.         if (scale_rate_x != 0) scaleX += scale_rate_x * 5e-4;
  157.         if (scale_rate_y != 0) scaleY += scale_rate_y * 5e-4;
  158.         if (alpha_rate != 0) alpha += alpha_rate * 5e-4;
  159.        
  160.         var rect:Rectangle = getBounds (_elements.root);
  161.         var action_flag:Boolean = false;
  162.         if (rect.left < 0.0){
  163.             velocity_x = Math.abs (velocity_x);
  164.             action_flag = true;}
  165.         else if (rect.right > 320){
  166.             velocity_x = -Math.abs (velocity_x);
  167.             action_flag = true;}
  168.         else if (rect.top < 0.0){
  169.             velocity_y = Math.abs (velocity_y);
  170.             action_flag = true;}
  171.         else if (rect.bottom > 480){
  172.             velocity_y = -Math.abs (velocity_y);
  173.             action_flag = true;}
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement