forked from: forked from: forked from: flash on 2009-8-12

by yooKo_old_account forked from forked from: forked from: flash on 2009-8-12 (diff: 190)
製作者
* yooko a.k.a (考え中) 
* 
* 自作サイト『SELFLASH』
* http://selflash.jp
* ブログ
* http://selflash.jp/blog * 
* 
* 
*  マウスの斜めに反応
♥0 | Line 152 | Modified 2009-08-13 17:52:17 | MIT License
play

ActionScript3 source code

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

// forked from yooKo's forked from: forked from: flash on 2009-8-12
// forked from yooKo's forked from: flash on 2009-8-12
// forked from yooKo's flash on 2009-8-12
/* 
 * 
 * 製作者
 * yooko a.k.a (考え中) 
 * 
 * 自作サイト『SELFLASH』
 * http://selflash.jp
 * ブログ
 * http://selflash.jp/blog * 
 * 
 * 
 *  マウスの斜めに反応
 */

package 
{
    import net.hires.debug.Stats;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.events.*;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import caurina.transitions.Tweener;
	
    public class FlashTest extends Sprite 
	{		
		// タイマー
		private var _timer:Timer;
		// スイッチ
		private var _swich1:int = 0;
		private var _swich2:int = 0;
		// テキスト
		private var _text:TextField;
		// ステージ上のマウスの座標
		private var _mouseX:Number;
		private var _mouseY:Number;
		// ステージ上のマウスの移動幅
		private var _Xidouhaba:Number;
		private var _Yidouhaba:Number;
		// マウスのxの移動幅とyの移動幅の差
		private var _kekka:Number;
		// 円
		private var _circle:Shape;
		
        public function FlashTest() 
		{
			// メモリの状況を調べる
			//addChild(new Stats());
			
			// 円を描画する
			_circle = new Shape();
			_circle.x = stage.stageWidth / 2;
			_circle.y = stage.stageHeight / 2;
			var _g:Graphics = _circle.graphics;
			_g.clear();
			_g.beginFill( 0x001133 );
			_g.drawCircle(0,0, 50);
			_g.endFill();
			addChild(_circle);
			
			// タイマーの設定
			_timer = new Timer(50);			
			_timer.addEventListener(TimerEvent.TIMER, _onKeisoku);
			
			/* _swichの状況を画面に表示する時にコメントアウトする
			 * 
			 */
			//_text = new TextField();
			//_text.text = "始まるよ";
			//_text.y = stage.stageHeight / 2;
			//_text.height = _text.textHeight + 100;
			//_text.width = _text.textWidth + 100;
			//addChild(_text);
			
			// タイマーの開始
			_timer.start();           
        }
		
		private function _onKeisoku(e:TimerEvent = null):void
		{	
			/*_swichの状況を画面に表示する時にコメントアウトする
			 * 
			 */
			//_text.appendText( "\nスイッチ1は" + _swich1 + "\nスイッチ2は" + _swich2);
			//_text.height = _text.textHeight + 20;
			//_text.width = _text.textWidth + 20;
			//_text.y -= 30;					
			
			// 前回のマウスの位置と今回のマウスの位置の差を計算する
			_Xidouhaba = stage.mouseX - _mouseX;
			_Yidouhaba = stage.mouseY - _mouseY;
			
			// stage上のマウスの位置を調べて_iXにとっておく
			_mouseX = stage.mouseX;
			_mouseY = stage.mouseY;
			
			_kekka = Math.abs( _Xidouhaba ) - Math.abs( _Yidouhaba ); 
			
			
			switch( _swich1 )
			{
				case 0:
				Tweener.addTween(_circle, { scaleX:1, scaleY:1, time:0.5, transition:"easeOutElastic" } );
				if ( _Xidouhaba > 40 && _Yidouhaba < - 40 )
				{
						_swich1 = 1;
				};
				break;
				
				case 1:
				if ( _Xidouhaba < -30 && _Yidouhaba > 30 )
				{
					_swich1 = 2;
				}else
				{
					_swich1 = 0;
				}
				break;
				
				case 2:
				if ( _Xidouhaba > 30 && _Yidouhaba < - 30 )
				{
					_swich1 = 3;
				}
				break;
				
				case 3:
				Tweener.addTween(_circle, { scaleX:1.5, scaleY:1.5, time:0.5, transition:"easeOutElastic" } );
				_swich1 = 0;
				break;				
			}
			
			
			switch( _swich2 )
			{
				 //マウスで描かれる円がyの移動から開始した時とxの移動から開始した場合で条件分岐させる
				case 0:
				 //yの移動から始まった時は 1 とする
				if ( 0 > _kekka )
				{
					_swich2 = 1;
				}
				 //xの移動から始まった時は 5 とする
				else if ( 0 < _kekka )
				{
					_swich2 = 5;
				}
				break;
				
				case 1:
				if ( 0 < _kekka )
				{
					_swich2 = 2;
				}else
				{
					_swich2 = 0;
				}
				break;
				
				case 2:
				if ( 0 > _kekka )
				{
					_swich2 = 3;
				}else
				{
					_swich2 = 0;
				}
				break;
				
				case 3:
				if ( 0 < _kekka )
				{
					_swich2 = 4;
				}else
				{
					_swich2 = 0;
				}
				break;
				
				case 4:
				 //マウスによる円の動きが完了した時の処理
				//_text.appendText("\nイベント開始!その1");
				Tweener.addTween(_circle, { x:Math.random() * stage.stageWidth, y:Math.random() * stage.stageHeight, time:0.5, transition:"easeOutElastic" } );
				 //処理が終わったらスイッチを 0 に戻す
				_swich2 = 0;
				break;				
				
				case 5:
				if ( 0 > _kekka )
				{
					_swich2 = 6;
				}else
				{
					_swich2 = 0;
				}
				break;
				
				case 6:
				if ( 0 < _kekka )
				{
					_swich2 = 7;
				}else
				{
					_swich2 = 0;
				}
				break;
				
				case 7:
				if ( 0 > _kekka )
				{
					_swich2 = 8;
				}else
				{
					_swich2 = 0;
				}
				break;
				
				case 8:
				 //マウスによる円の動きが完了した時の処理
				//_text.appendText("\nイベント開始!その2");
				Tweener.addTween(_circle, { x:Math.random() * stage.stageWidth, y:Math.random() * stage.stageHeight, time:0.5, transition:"easeOutElastic" } );				
				 //処理が終わったらスイッチを 0 に戻す
				_swich2 = 0;
				break;
				
			}			
		}
    }
}