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

あれやこれや投げ出したいとき

つくりかけ。
@author naoto koshikawa
Get Adobe Flash player
by naoto5959 16 Jan 2009
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.getTimer;
	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="24")]  

	/**
	 * つくりかけ。
	 * @author naoto koshikawa
	 */
	public class Main3 extends MovieClip
	{
		// _____________________________________________________ Property
		private static const MOTION_TEXT:String = "あれやこれや";
		
		private var _textIndex:uint;
		
		private var _textContainer:Sprite;
		
		private var _prevTimer:uint;
		
		// _____________________________________________________ Method
		public function Main3() 
		{
			_prevTimer = getTimer();
			_textContainer = new Sprite();
			_textContainer.x = stage.stageWidth / 2;
			_textContainer.y = stage.stageHeight / 2;
			addChild(_textContainer);
			drawDotLayer();
			addEventListener(Event.ENTER_FRAME, enterFrameListener);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
			stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
		}
		
		/**
		 * draw doted layer
		 */
		private function drawDotLayer():void
		{
			var bitmapData:BitmapData = new BitmapData(2, 2, true, 0x00FFFFFF);
			bitmapData.setPixel32(0, 0, 0x33EFEFEF);
			
			var shape:Shape = new Shape();
			var gr:Graphics = shape.graphics;
			gr.beginBitmapFill(bitmapData, null, true, false);
			gr.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			addChild(shape);
		}
		
		/**
		 * make textField
		 */
		private function makeText():DisplayObject
		{
			// pick up text
			var char:String = MOTION_TEXT.charAt(_textIndex);
			if (++_textIndex >= MOTION_TEXT.length) _textIndex = 0;
			
			// create TextField and add to container
			var textField:TextField = new TextField();
			textField.defaultTextFormat = new TextFormat("_等幅", 18, 0xFFFF0000 | 0x00008888 * Math.random() | 0x00008888);
			textField.text = char;
			var mc:MovieClip = new MovieClip();
			var bitmapData:BitmapData = new BitmapData(textField.textWidth, textField.textHeight, true, 0x00000000);
			bitmapData.draw(textField, null, null, null, null, true);
			var bitmap:Bitmap = new Bitmap(bitmapData);
			var scale:Number = Math.random() * 0.5 + 0.5;
			mc.addChild(bitmap);
			mc.x = _textContainer.mouseX;
			mc.y = _textContainer.mouseY;
			mc.origin = new Point(mc.x, mc.y);
			mc.acc = new Point(0, 0);
			mc.speed = new Point(0, 0);
			mc.radian = Math.random() * Math.PI * 1 / 4 - Math.PI * 5 / 8;
			mc.scaleX = mc.scaleY = mc.alpha = scale;
			return mc;
		}
		
		// _____________________________________________________ Listener
		private function enterFrameListener(event:Event):void
		{
			var t:Number = (getTimer() - _prevTimer) / 1000;
			var i:int;
			var mc:MovieClip;
			for (i = 0; i < 3; i++)
			{
				 mc = makeText() as MovieClip;
				_textContainer.addChild(mc);
			}
			// text motion
			for (i = _textContainer.numChildren-1; i >= 0; i--)
			{
				mc = _textContainer.getChildAt(i) as MovieClip;
				var dist:uint = Point.distance(new Point(mc.x, mc.y), mc.origin);
				var acc:uint =  Math.random() * 30 + 30;
				
				mc.acc.x = acc * Math.cos(mc.radian);
				mc.acc.y = acc * Math.sin(mc.radian);
				mc.acc.y += 9.8;
				
				mc.radian = Math.atan2(mc.acc.y, mc.acc.x);
				if (-Math.PI <= mc.radian && mc.radian <= -Math.PI / 2)
				{
					mc.rotation += 5;
				}
				else ( -Math.PI / 2 <= mc.radian && mc.radian <= 0)
				{
					mc.rotation -= 5;
				}
				
				// change mc status
				mc.x += mc.speed.x * t + 0.5 * mc.acc.x + Math.pow(t, 2);
				mc.y += mc.speed.y * t + 0.5 * mc.acc.y + Math.pow(t, 2);
				
				
				if (mc.x < -stage.stageWidth / 2 || stage.stageWidth / 2 < mc.x) _textContainer.removeChildAt(i);
				if (stage.stageHeight / 2 < mc.y) _textContainer.removeChildAt(i);
				
				mc.speed.x += mc.acc.x * t;
				mc.speed.y += mc.acc.y * t;
				
				mc.speed.x *= 0.9;
				mc.speed.y *= 0.9;
				
				mc.acc.x = 0;
				mc.acc.y = 0;
			}
			_prevTimer = getTimer();
		}
		private function mouseDownListener(event:MouseEvent):void
		{
			removeEventListener(Event.ENTER_FRAME, enterFrameListener);
		}
		private function mouseUpListener(event:MouseEvent):void
		{
			addEventListener(Event.ENTER_FRAME, enterFrameListener);
		}
	}
}