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

追加と削除の練習

Get Adobe Flash player
by nabe 25 Feb 2010
    Embed
/**
 * Copyright nabe ( http://wonderfl.net/user/nabe )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zSLB
 */

package {
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	public class Main extends Sprite {
		public function Main ():void {
			if (stage) {
				init_(null);
			} else {
				addEventListener(Event.ADDED_TO_STAGE, init_);
			}
		}
		private function init_(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init_);
			var button_:Button = new Button;
			button_.addEventListener(MouseEvent.CLICK, append_);
			addChild(button_);
			append_(null);
		}
		private function append_(e:Event):void {
			addChildAt(new Circle, 0);
		}
	}
}

import flash.display.GradientType;
import flash.display.Graphics;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.events.Event;
class Button extends TextField {
	public function Button():void {
		var format_:TextFormat = new TextFormat;
		format_.size = 24;
		format_.leftMargin = 12;
		format_.rightMargin = 12;
		format_.color = 0x0;
		defaultTextFormat = format_;
		text = "AddNew";
		autoSize = TextFieldAutoSize.LEFT;
		border = true;
		borderColor = 0x0;
		background = true;
		backgroundColor = 0xCCFFFF;
		selectable = false;
	}
}
class Circle extends Sprite {
	public function Circle():void {
		if (stage) {
			init_(null);
		} else {
			addEventListener(Event.ADDED_TO_STAGE, init_);
		}
	}
	private function init_(e:Event):void {
		removeEventListener(Event.ADDED_TO_STAGE, init_);
		x = stage.stageWidth * Math.random();
		y = stage.stageHeight * Math.random();
		draw_();
		addEventListener(MouseEvent.CLICK, remove_);
	}
	private function draw_():void {
		const r_:int = 100;
		var m_:Matrix = new Matrix;
		m_.createGradientBox(r_ * 2, r_ * 2, Math.PI * 0.25, -r_, -r_);
		var g_:Graphics = graphics;
		g_.clear();
		g_.beginGradientFill(GradientType.RADIAL, [0xFFFFFF, 0xFF0000, 0xCC3333], null, [0x4, 0xD0, 0xFF], m_, "pad", "rgb", -0.25);
		g_.drawCircle(0, 0, r_);
		g_.endFill();
	}
	private function remove_(e:Event):void {
		parent.removeChild(this);
	}
}