In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Balloon

元ネタ
http://www.bit-101.com/flafiles/
Get Adobe Flash player
by hacker_3szp8277 16 Jan 2009
    Embed
/*
元ネタ
http://www.bit-101.com/flafiles/
*/


package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class Balloon extends Sprite
	{
		private var numBalls:int = 20;
		private var i:int;
		private var balls:Array=new Array;
		public function Balloon()
		{
			for (i=0; i<numBalls; i++) {
				
				var b:ball;
				if (i!=0) {
					b = new ball(false);//attachMovie("ball", "b"+i, i);
					b.twin = balls[i-1];//_root["b"+(i-1)];
					b.visible=false;
				}else{
					b = new ball(true);
				}
				balls.push(b);
				addChild(b);
				b.x = Math.random()*10+265;
				b.y = 150;
			}
			addEventListener(Event.ENTER_FRAME,onEnterFrame);
		}


		private function onEnterFrame(e:Event):void {
			graphics.clear();
			graphics.lineStyle(1, 0, 1);
			graphics.moveTo(balls[0].x, balls[0].y);
			for (var i:int=1; i<numBalls; i++) {
				graphics.lineTo(balls[i].x, balls[i].y);
			}
			if(balls[0].drag){
				balls[0].x = mouseX;
				balls[0].y = mouseY+15;
			}
		};
	}
}
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	

class ball extends Sprite{
	private const k:Number = 0.2;
	private const grav:Number = 0.01;
	private const damp:Number = 0.9;
	public function ball(b:Boolean){
		if(b){
			graphics.beginFill(0xff);
			graphics.drawEllipse(-10,-30,20,30);
			graphics.endFill();
			addEventListener(MouseEvent.MOUSE_DOWN,doDrag);
			addEventListener(MouseEvent.MOUSE_UP,noDrag);
		}
		addEventListener(Event.ENTER_FRAME,ballMove);
	}
	public var twin:ball;
	public var drag:Boolean;
	public var vx:Number=0;
	public var vy:Number=0;
	public var oldx:Number=0;
	public var oldy:Number=0;

	public function ballMove(e:Event):void {
		if (!drag) {
			if (twin) {
				var ax:Number = (twin.x-x)*k;
				var ay:Number = (twin.y+10-y)*k;
				vx += ax;
				vy += ay;
				twin.vx -= ax;
				twin.vy -= ay;
				vx *= damp;
				vy *= damp;
			}else{
				vy-=grav;
			}
			x += vx;
			y += vy;
			if (y<70) {
				y = 70;
				vy *= -1;
			}
		} else {
			vx = x-oldx;
			vy = y-oldy;
			oldx = x;
			oldy = y;
		}
	}
	public 	function doDrag(e:MouseEvent):void {
		drag = true;
	}
	public	function noDrag(e:MouseEvent):void {
		drag = false;
	}
}