Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.Rectangle;
- public class Movie14 extends Sprite
- {
- public var next_frame:int = 1;
- public var total_frames:int = 3;
- public var current_frame:int = -1;
- public var is_playing:Boolean = true;
- public var frame_labels:Array = ["Scene 1"];
- public var frame_numbers:Array = [1];
- public function Movie14()
- {
- _elements.root = this;
- _elements.paint7 = new CPaint7;
- addChild (_elements.paint7);
- addEventListener ("enterFrame", onEnterFrame);
- }
- public function restart():void
- {
- for (var i:int=0; i<_elements; i++){
- var e:* = _elements[i];
- if (e.hasOwnProperty("reset")) e.reset();}
- gotoAndPlay (0);
- }
- public function play ():void { is_playing = true;}
- public function stop ():void { is_playing = false; next_frame = current_frame;}
- public function start ():void { is_playing = true; next_frame = 0;}
- public function gotoAndPlay (frame:*):void { is_playing = true; next_frame = getFrameNumber (frame);}
- public function gotoAndStop (frame:*):void { is_playing = false; next_frame = getFrameNumber (frame);}
- public function getFrameNumber (frame:*):int
- {
- var i:int = frame_labels.indexOf (frame);
- if (i == -1) return frame;
- return frame_numbers[i];
- }
- public function placeImage (image:*, frame:int):void
- {
- var i:int = image.frames.indexOf(frame);
- while (i > -1 && i < image.frames.length && image.frames[i] == frame){
- var j:int = image.indices[i++];
- var t:int = image.places[j++];
- if (t & 1) image.x = image.places[j++];
- if (t & 2) image.y = image.places[j++];
- if (t & 4) image.scaleX = image.places[j++] / 100;
- if (t & 8) image.scaleY = image.places[j++] / 100;
- if (t & 16) image.alpha = image.places[j++] / 100;
- if (t & 32) image.rotation = image.places[j++];
- if (t & 64) image.visible = image.places[j++];
- if (t & 128) image.play();}
- }
- public function onEnterFrame (_e:Event):void
- {
- for (var _i:int=poll_objects.length-1; _i>=0; _i--){
- var _obj:* = poll_objects[_i];
- _obj.poll (0.05);}
- var new_frame:Boolean = false;
- if (current_frame != next_frame){
- current_frame = next_frame;
- new_frame = true;}
- if (is_playing){
- if (++next_frame >= 3) next_frame = 0;}
- if (new_frame){
- placeImage (_elements.paint7, current_frame);
- if (current_frame == 2) onFrame2 (_e);
- }
- }
- public function onFrame2 (_e:Event):void
- {
- stop ();
- }
- }
- }
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.Rectangle;
- var _elements:Object = new Object;
- var poll_objects:Array = new Array;
- class CPaint7 extends Sprite
- {
- public var velocity_x:Number = 40;
- public var velocity_y:Number = 40;
- public var acceleration_x:Number = 0.0;
- public var acceleration_y:Number = 0.0;
- public var scale_rate_x:Number = 0.0;
- public var scale_rate_y:Number = 0.0;
- public var alpha_rate:Number = 0.0;
- public var friction_x:Number = 0.0;
- public var friction_y:Number = 0.0;
- public var angular_velocity:Number = 0.0;
- public var angular_acceleration:Number = 0.0;
- public var angular_friction:Number = 0.0;
- [Embed(source="paint7.swf")]
- public var Paint7:Class;
- public var clone_parent:* = null;
- public var clone_array:Array = new Array;
- public var frames:Array = [0];
- public var indices:Array = [0];
- public var places:Array = [127,160,240,100,100,100,0,true];
- public function CPaint7()
- {
- name = "Paint 7";
- x = 160;
- y = 240;
- addChild (new Paint7);
- addEventListener ("enterFrame", onEnterFrame);
- }
- function physics (velocity:Number, acceleration:Number, maximum:Number, friction:Number):Number
- {
- if (acceleration != 0.0) velocity += acceleration * 0.05;
- if (friction > 0.0){
- if (velocity > 0.0){
- velocity -= friction * 0.05;
- if (velocity < 0.0) velocity = 0.0;}
- else if (velocity < 0.0){
- velocity += friction * 0.05;
- if (velocity > 0.0) velocity = 0.0;}}
- if (maximum > 0.0){
- if (velocity > maximum) velocity = maximum;
- if (velocity < -maximum) velocity = -maximum;}
- return velocity;
- }
- public function reset():void
- {
- if (hasOwnProperty ("places")) _elements.root.placeImage (this, 0);
- }
- public function clone():*
- {
- var _c:CPaint7 = new CPaint7;
- parent.addChildAt (_c, parent.getChildIndex (this) + 1);
- clone_array.push (_c);
- _c.clone_parent = this;
- return _c;
- }
- public function onEnterFrame (_e:Event):void
- {
- if (velocity_x != 0) x += velocity_x * 0.05;
- if (velocity_y != 0) y += velocity_y * 0.05;
- if (angular_velocity != 0) rotation += angular_velocity * 0.05;
- velocity_x = physics (velocity_x, acceleration_x, 0.0, friction_x);
- velocity_y = physics (velocity_y, acceleration_y, 0.0, friction_y);
- angular_velocity = physics (angular_velocity, angular_acceleration, 0.0, angular_friction);
- if (scale_rate_x != 0) scaleX += scale_rate_x * 5e-4;
- if (scale_rate_y != 0) scaleY += scale_rate_y * 5e-4;
- if (alpha_rate != 0) alpha += alpha_rate * 5e-4;
- var rect:Rectangle = getBounds (_elements.root);
- var action_flag:Boolean = false;
- if (rect.left < 0.0){
- velocity_x = Math.abs (velocity_x);
- action_flag = true;}
- else if (rect.right > 320){
- velocity_x = -Math.abs (velocity_x);
- action_flag = true;}
- else if (rect.top < 0.0){
- velocity_y = Math.abs (velocity_y);
- action_flag = true;}
- else if (rect.bottom > 480){
- velocity_y = -Math.abs (velocity_y);
- action_flag = true;}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement