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 siba
Get Adobe Flash player
by siba2260 18 Dec 2008
// forked from siba2260's code on 2008-12-18
// write as3 code here..
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	
	[SWF(width=800, height=600, backgroundColor=0xAADDFF)]

	/**
	 * 残像エフェクト。
	 * @author siba
	 */
	public class Main17 extends Sprite {
		
		// ----------------------------
		//	メンバ変数
		// ----------------------------
		
		private var afterBitmapData:BitmapData = new BitmapData(800, 600, true, 0x00FFFFFF);
		private var afterImage:Bitmap = new Bitmap(afterBitmapData, PixelSnapping.AUTO, true);
		private var character:Character = new Character();
		
		
		// ----------------------------
		//	初期化
		// ----------------------------
		
		public function Main17() {
			addChild(afterImage);
			
			character.x = 200;
			character.y = 200;
			addChild(character);
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		
		// ----------------------------
		//	イベント
		// ----------------------------
		
		private function onEnterFrame(event:Event):void {
			character.move();
			
			afterBitmapData.colorTransform(afterBitmapData.rect, 
						new ColorTransform(1, 1, 1, 1, 0, 0, 0, -16));
			
			var mat:Matrix = new Matrix();
			mat.translate(character.x, character.y);
			afterBitmapData.draw(character, mat);
		}
		
	}
}


// ------------------------------------
//	内部クラス
// ------------------------------------

import flash.display.Sprite;
import flash.events.Event;

class Character extends Sprite {
	
	// --------------------------------
	//	メンバ変数
	// --------------------------------
	
	private var isStage:Boolean = false;
	private var vx:Number = 5;
	private var vy:Number = 5;
	
	
	// --------------------------------
	//	初期化
	// --------------------------------
	
	public function Character() {
		graphics.beginFill(0x0000FF);
		graphics.drawCircle(0, 0, 50);
		graphics.endFill();
		
		graphics.beginFill(0x00FF00);
		graphics.drawCircle(0, 0, 20);
		graphics.endFill();
		
		addEventListener(Event.ADDED_TO_STAGE, onAddedStage);
	}
	
	
	// --------------------------------
	//	パブリック
	// --------------------------------
	
	public function move():void {
		x += vx;
		y += vy;
		
		if (isStage) {
			if (x < 0+width/2 || x > stage.stageWidth-width/2) {
				vx *= -1;
			}
			if (y < 0+height/2 || y > stage.stageHeight-height/2) {
				vy *= -1;
			}
		}
	}
	
	
	// --------------------------------
	//	イベント
	// --------------------------------
	
	private function onAddedStage(event:Event):void {
		isStage = true;
	}
	
}