flash on 2009-8-4

by kamip
flashはじめました
* いろいろ分かりませんが適当なブログ書いてます
* http://d.hatena.ne.jp/kamip/20090803
* 上のボタンがスタートで下のボタンがストップ
* これを元に勉強してみます、、
♥0 | Line 85 | Modified 2009-08-04 02:08:26 | MIT License
play

ActionScript3 source code

/**
 * Copyright kamip ( http://wonderfl.net/user/kamip )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nhFu
 */

/**
 * flashはじめました
 * いろいろ分かりませんが適当なブログ書いてます
 * http://d.hatena.ne.jp/kamip/20090803
 * 上のボタンがスタートで下のボタンがストップ
 * これを元に勉強してみます、、
 */

package  
{
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author kamip
	 */
	[SWF(backgroundColor = "0x666666", width = "400", height = "250", frameRate = "10")]
	
	public class Circle extends Sprite
	{
		private var start:SimpleButton;
		private var stop:SimpleButton;
		private var rec:Sprite;
		private var count:int = 0;
		private var line:Shape;
		private var sw:Boolean = true;
		private var r:Number = 10;
		
		public function Circle() 
		{
			init();
		}
		private function init():void {
			// startボタンの作成
			start = new SimpleButton();
			start.x = 10;
			start.y = -10;
			start.upState = makeRoundRect(0x228822);
			start.overState = makeRoundRect(0x225522);
			start.downState = makeRoundRect(0x553355);
			start.hitTestState = start.upState;
			start.name = "start";
			addChild(start);
			// stopボタンの作成
			stop = new SimpleButton();
			stop.x = 10;
			stop.y = 20;
			stop.upState = makeRoundRect(0x228822);
			stop.overState = makeRoundRect(0x225522);
			stop.downState = makeRoundRect(0x553355);
			stop.hitTestState = stop.upState;
			stop.name = "stop";
			addChild(stop);
			// キャンパスを作成
			rec = new Sprite();
			rec.graphics.beginFill(0x00ffffff);
			rec.graphics.drawRect(10, 55, 380, 180);
			rec.graphics.endFill();
			addChild(rec);
			// これが円かな
			line = new Shape();
			rec.addChild(line); // 円をキャンパスにaddChild
			// イベント
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			start.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			stop.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
		}
		
		// onEnterFrameイベント
		private function onEnterFrame(event:Event):void {
			if (sw) {
				count++;
				line.graphics.lineStyle(1);
				line.graphics.drawCircle(10 + r, 55 + r, r);
				r = 1.1 * r;
				if (count > 50) {
					line.graphics.clear();
					count = 0;
					r = 10;
				}
			}
		}
		
		// onMouseDownイベント
		private function onMouseDown(event:MouseEvent):void {
			if (sw) {
				if (event.target.name == "stop") {
					sw = false;
				}
			}else {
				if (event.target.name == "start") {
					sw = true;
				}
				
			}
		}
		// 拡張現実ライフさんから拝借
		private function makeRoundRect(color:uint):Sprite{
			var s:Sprite = new Sprite();
			s.graphics.beginFill(color);
			s.graphics.drawRoundRect(0, 0, 50, 20, 10);
			s.graphics.endFill();
			s.alpha = 0.8;
			return s;
		}
		
	}
	
}