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

forked from: あの楽器っぽいスクリプト Ver1.2(メニューをつけてみた)

懲りずにセルフフォーク

メニューとボリューム機能をつけてみました。

ただ、ボリュームはsoundをplayしたら1に戻るんですね。
で、play後にsoundChannelでVolumeを設定すると
冒頭の発音がおかしくなるという。どうしたものでしょうか。

あと、音色を少し追加。
擬似三角波はプログラムの性質上、音程が
上がるにつれて擬似の意味がなくなります。
Noiseは短周波ノイズがいまいちわからなかったので
?が付いてます。これじゃ長周波ノイズの周波数が
少し短いだけのような感じですね。
もっと、ビーッてなる感じの音のはずなのですが・・・。

ASだけでメニューの動きを作ろうとすると面倒ですね。

あとは構築の仕方が下手すぎるなと痛感しました。
他の方のコードを見て学ばないと・・・。
// forked from Hiiragi's あの楽器っぽいスクリプト Ver1.2(メニューをつけてみた)
package 
{
	 /*
	  * 懲りずにセルフフォーク
	  * 
	  * メニューとボリューム機能をつけてみました。
	  * 
	  * ただ、ボリュームはsoundをplayしたら1に戻るんですね。
	  * で、play後にsoundChannelでVolumeを設定すると
	  * 冒頭の発音がおかしくなるという。どうしたものでしょうか。
	  * 
	  * あと、音色を少し追加。
	  * 擬似三角波はプログラムの性質上、音程が
	  * 上がるにつれて擬似の意味がなくなります。
	  * Noiseは短周波ノイズがいまいちわからなかったので
	  * ?が付いてます。これじゃ長周波ノイズの周波数が
	  * 少し短いだけのような感じですね。
	  * もっと、ビーッてなる感じの音のはずなのですが・・・。
	  * 
	  * ASだけでメニューの動きを作ろうとすると面倒ですね。
	  * 
	  * あとは構築の仕方が下手すぎるなと痛感しました。
	  * 他の方のコードを見て学ばないと・・・。
	  */
	 
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.SampleDataEvent;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	[SWF(width="465", height="465", frameRate="30", backgroundColor="#ffffff")]

	public class Main extends Sprite 
	{
		//ステージ上描画関連
		private var _baseSp:Sprite;
		private var _baseSpGrid:Sprite;
		private var _blackKeyArray:Array = new Array();
		
		public static var tF:TextField;
		private var button:Sprite;
		private var buttonText:TextField;
		
		private var _dragFlag:Boolean;
		
		//サウンドオブジェクト関連
		public static var _soundCh:SoundChannel;
		private var _soundObj:Sound;
		
		//音関連
		private var _phase:Number = 0;
		private var _buffSize:Number = 2048;
		private var _targetFreq:Number;
        private var _freq:Number = 0;
		private var _baseFreq:Number = 440;
		public static var _volume:Number = .4;
		private var _buffer:uint = 2048;
		private var _noiseFreqFlag:uint = 1;
		
        private const PI2:Number = Math.PI * 2;
		private const PI:Number = Math.PI;
		
		private var _mouseX:Number;
		private var _mouseY:Number;
		
		private var keyArray:Array = [130.8,146.8,164.8,174.6,196.0,220.0,246.9,261.6, 293.7, 329.6, 349.2, 392.0, 440, 493.9,523.3];
		private var _keyBaseFreq:uint;
		private var _movCnt:uint;	//図形を出すためのカウント変数
		private var _movCntMax:uint = 15;
		private const POWER:Number = Math.pow(2, 1 / 13);	//X軸で音階を変えるのに必要
		private var num:uint = 24;	//音階の数
		
		private var _flag:int;	//現在の図形の種類
		public static var _waveTone:uint = 0;	//現在の音の種類
		public static var _waveToneArray:Array = ["SineWave",
										"SquareWave(50:50)",
										"SquareWave(25:75)",
										"SquareWave(12.5:87.5)",
										"TriangleWave",
										"TriangleWave(FC?)",
										"Saw Wave",
										"Noise(Long)",
										"Noise(Short)?"]

		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			//ステージ上の描画
			_baseSp = new Sprite();
			_baseSp.x = _baseSp.y = 0;
			_baseSp.graphics.beginFill(0x000000, 1);
			_baseSp.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			_baseSp.graphics.endFill();
			addChild(_baseSp);
			
			
			
			
			//鍵盤描画(黒鍵)
			for (var j:uint = 0; j < 4; j++) {
				_blackKeyArray[j] = new Array();
				drawBlackKey(21, j * 116, 138.6,_blackKeyArray[j]);
				drawBlackKey(52, j * 116, 155.5,_blackKeyArray[j]);
				drawBlackKey(114, j * 116, 185,_blackKeyArray[j]);
				drawBlackKey(145, j * 116, 207.7,_blackKeyArray[j]);
				drawBlackKey(176, j * 116, 233.1,_blackKeyArray[j]);
				drawBlackKey(238, j * 116, 277.2,_blackKeyArray[j]);
				drawBlackKey(269, j * 116, 311.2,_blackKeyArray[j]);
				drawBlackKey(331, j * 116, 370,_blackKeyArray[j]);
				drawBlackKey(362, j * 116, 415.3,_blackKeyArray[j]);
				drawBlackKey(393, j * 116, 466.2,_blackKeyArray[j]);
			}
			
			//鍵盤描画(横線)
			_baseSpGrid = new Sprite();
			_baseSpGrid.graphics.lineStyle(0.5, 0x333333);
			_baseSpGrid.graphics.moveTo(0, 0);
			_baseSpGrid.graphics.lineTo(465, 0);
			_baseSpGrid.graphics.moveTo(0, 116);
			_baseSpGrid.graphics.lineTo(465, 116);
			_baseSpGrid.graphics.moveTo(0, 232);
			_baseSpGrid.graphics.lineTo(465, 232);
			_baseSpGrid.graphics.moveTo(0, 348);
			_baseSpGrid.graphics.lineTo(465, 348);
			_baseSpGrid.graphics.moveTo(0, 465);
			_baseSpGrid.graphics.lineTo(465, 465);
			addChild(_baseSpGrid);
			
			//波形情報表示関連
			tF = new TextField();
			tF.autoSize = TextFieldAutoSize.LEFT;
			tF.defaultTextFormat = new TextFormat(null, 22, 0xFFFFFF);
			tF.text = _waveToneArray[_waveTone];
			_baseSp.addChild(tF);
			
			button = new Sprite();
			button.buttonMode = true;
			button.mouseChildren = false;
			button.graphics.beginFill(0x6666FF);
			button.graphics.drawRoundRect(0, 0, 100, 30,10);
			button.graphics.endFill();
			button.x = 10;
			button.y = 50;
			//addChild(button);
			
			buttonText = new TextField();
			buttonText.autoSize = TextFieldAutoSize.CENTER;
			buttonText.defaultTextFormat = new TextFormat(null, 20, 0xFFFFFF);
			buttonText.text = "Change";
			buttonText.selectable = false;
			button.addChild(buttonText);
			
			button.addEventListener(MouseEvent.CLICK, onButtonClick);
			
			
			//サウンド関連
			_soundCh = new SoundChannel();
			_soundObj = new Sound();
			
			//セッティングウィンドウ
			var setting:settingWindow = new settingWindow();
			setting.x = 270;
			addChild(setting);
			
			//いろいろ
			_dragFlag = false;
			_baseSp.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
			_baseSp.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
			_baseSp.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
			_baseSp.mouseChildren = false;
			_mouseX = stage.mouseX;
			_mouseY = stage.mouseY;
			
		}
		
		//Draw系Function
		private function drawBlackKey(tx:Number,ty:Number,hz:Number,arr:Array):void
		{
			var sp:Sprite = new Sprite();
			sp.graphics.beginFill(0x000000);
			sp.graphics.lineStyle(0.5,0x222222);
			sp.graphics.moveTo(0, 0);
			sp.graphics.lineTo(20, 0);
			sp.graphics.lineTo(20, 70);
			sp.graphics.lineTo(0, 70);
			sp.graphics.lineTo(0, 0);
			sp.graphics.endFill();
			sp.name = hz.toString();
			sp.x = tx;
			sp.y = ty;
			_baseSp.addChild(sp);
			arr.push(sp);
		}
		
		private function onButtonClick(e:MouseEvent = null):void 
		{
			_waveTone += 1;
			if (_waveTone > 8) _waveTone = 0;
			
			toneTextChange();
			
		}
		
		public static function toneTextChange():void
		{
			tF.text = _waveToneArray[_waveTone];
		}
		
		private function drawBitmap(flagNum:int,e:MouseEvent):void
		{
			var drawSp:MovieClip = new MovieClip();
			
			if (flagNum == -1) _flag = Math.floor(Math.random() * 5);
			else _flag = flagNum;
			
			drawSp.graphics.beginFill(0x66FF66);
			
			switch (_flag) 			
			{
				case 0:
					drawSp.graphics.drawCircle( 0, 0, 50);
					drawSp.graphics.drawCircle( 0, 0, 47.5);
					break;
				case 1:
					drawStar(drawSp,0, 0, 50);
					drawStar(drawSp,0, 0, 45);
					break;
				case 2:
					drawSp.graphics.drawRect(-50,-50,100,100);
					drawSp.graphics.drawRect( -47.5, -47.5, 95, 95);

					break;
				case 3:
					drawLineBmp();
					break;
				case 4:
					drawTriangle(drawSp);
			}
			drawSp.graphics.endFill();
			
			drawSp.x = e.stageX;
			drawSp.y = e.stageY;
			drawSp.rotation = Math.random() * 360;
			_baseSp.addChild(drawSp);
			drawSp.addEventListener(Event.ENTER_FRAME, bmpFadeOut);
			
			
			
		}
		
		private function drawLineBmp():void 
		{
			var drawLineSp:MovieClip = new MovieClip();
			drawLineSp.x = _mouseX;
			drawLineSp.y = _mouseY;
			
			drawLineSp.graphics.lineStyle(Math.random() * 30 + 5, 0x66FF66);
			
			drawLineSp.graphics.moveTo(-657, 0);
			drawLineSp.graphics.lineTo(657, 0);
			drawLineSp.rotation = Math.random() * 360;
			_baseSp.addChild(drawLineSp);
			drawLineSp.addEventListener(Event.ENTER_FRAME, bmpFadeOutNoRotation);
		}
		
		private function drawTriangle(drawSp:Sprite):void 
		{
			drawSp.graphics.beginFill(0x66FF66);
			drawSp.graphics.moveTo(0, -43.4);
			drawSp.graphics.lineTo(50, 43.4);
			drawSp.graphics.lineTo(-50, 43.4);
			drawSp.graphics.lineTo(0, -43);
			drawSp.graphics.moveTo(0, -39.05);
			drawSp.graphics.lineTo(45, 41);
			drawSp.graphics.lineTo(-45, 41);
			drawSp.graphics.lineTo(0, -39.05);
			
		}
		
		private function drawStar(sp:Sprite,drawX:Number = 0,drawY:Number = 0,drawScale:Number = 50):void
		{
			var scale:Number = drawScale / 50;
			sp.graphics.lineStyle(0.5,0x66FF66,0.5);
			sp.graphics.moveTo(0.3*scale , -47.65*scale);
			sp.graphics.lineTo(12.5*scale, -12.2*scale);
			sp.graphics.lineTo(50*scale, -10.95*scale);
			sp.graphics.lineTo(20.05*scale, 11.6*scale);
			sp.graphics.lineTo(30.45*scale, 47.65*scale);
			sp.graphics.lineTo( -0.3*scale , 26.15*scale);
			sp.graphics.lineTo( -31.35*scale , 47.15*scale);
			sp.graphics.lineTo( -20.4*scale , 11.3*scale);
			sp.graphics.lineTo(-50*scale, -11.75*scale);
			sp.graphics.lineTo( -12.45*scale , -12.4*scale);
			sp.graphics.lineTo(0.3*scale, -47.65*scale);
		}
		
		private function bmpFadeOutNoRotation(e:Event):void 
		{
			var mc:MovieClip = e.target as MovieClip;
			mc.alpha -= 0.08;
			if (mc.alpha <= 0) {
				mc.removeEventListener(Event.ENTER_FRAME, bmpFadeOutNoRotation);
				_baseSp.removeChild(mc);
			}
		}
		
		
		private function bmpFadeOut(e:Event):void 
		{
			var mc:MovieClip = e.target as MovieClip;
			mc.alpha -= 0.08;
			mc.rotation += 10;
			mc.scaleX = mc.scaleY += 0.4;
			if (mc.alpha <= 0) {
				mc.removeEventListener(Event.ENTER_FRAME, bmpFadeOut);
				_baseSp.removeChild(mc);
				
			}
		}
		
		//Intaractive系Function
		private function mouseDownHandler(e:MouseEvent):void 
		{
			_dragFlag = true;
			_mouseX = stage.mouseX;
			_mouseY = stage.mouseY;

			changeFreqency();
			_soundObj.addEventListener(SampleDataEvent.SAMPLE_DATA, toneGenerate);
			//_soundCh.soundTransform = new SoundTransform(_volume);
			//trace(_soundCh.soundTransform.volume);
			_soundCh = _soundObj.play();
			_soundCh.soundTransform = new SoundTransform(_volume);
			//trace(_soundCh.soundTransform.volume);
			
			drawBitmap( -1, e);
			
			stage.addEventListener(Event.ENTER_FRAME, changeFreqency);
		}
		
		private function mouseUpHandler(e:MouseEvent):void 
		{
			_dragFlag = false;
			_movCnt = 0;
			_soundObj.removeEventListener(SampleDataEvent.SAMPLE_DATA, toneGenerate);
			_soundCh.stop();
			_flag = -1;
			stage.removeEventListener(Event.ENTER_FRAME, changeFreqency);
		}
		
		private function mouseMoveHandler(e:MouseEvent):void 
		{
			if (_dragFlag) {
				_movCnt++;
				if (_movCnt >= _movCntMax) {
					_movCnt = 0;
					drawBitmap(_flag,e);
				}
			}
		}
		
		//sound系Function
		private function changeFreqency(e:Event = null):void
		{
			_mouseX = stage.mouseX;
			_mouseY = stage.mouseY;
			
			if (_mouseX <= 0) _mouseX = 1;
			else if (_mouseX >= 465) _mouseX = 464;
			
			if (_mouseY <= 0) _mouseY = 1;
			else if (_mouseY >= 465) _mouseY = 464;

			var position:uint = Math.floor(stage.mouseX / 31);
			var centerPoint:Number = 31 * position + 16;
			
			_keyBaseFreq = 0;
			

			var posY:uint = Math.floor(_mouseY / 116.25);
			_blackKeyArray[posY].forEach(blackKeyCheck);
			
			if (_keyBaseFreq == 0) {
				_keyBaseFreq = keyArray[position];
			}
			
			if (_mouseY < 116) {
				_targetFreq = _keyBaseFreq * 4;
				_noiseFreqFlag = 4;
			} else if (_mouseY < 232) {
				_targetFreq = _keyBaseFreq * 2;
				_noiseFreqFlag = 3;
			} else if (_mouseY < 348) {
				_targetFreq = _keyBaseFreq;
				_noiseFreqFlag = 2;
			} else {
				_targetFreq = _keyBaseFreq / 2;
				_noiseFreqFlag = 1;
			}
			
			_freq = _targetFreq;
		}
		
		private function blackKeyCheck(element:*,i:int,arr:Array):void
		{
			if (element.hitTestPoint(_mouseX, _mouseY, true)) {
				_keyBaseFreq = Number(element.name);
			}
		}
		
		
		private function toneGenerate(e:SampleDataEvent):void
		{
			var _noiseCnt:uint = 0;
			var _noiseCntMax:uint;
			var shortNoiseFreq:Number;
			if (_waveTone == 7 || _waveTone == 8) {
				if (_waveTone == 7) {
					_noiseCntMax = Math.ceil(_mouseY / 20);
					shortNoiseFreq = Math.random() * 2 - 1;
				} else if (_waveTone == 8) {
					_noiseCntMax = Math.ceil(_buffer / (_buffer / 60)) / ((465 - _mouseY) / 160 * 2);
					shortNoiseFreq = Math.random() * 2 - 1;
				}
			}
			
			
			
            for (var i:int = 0; i < _buffer; ++i) {
				
				var smpl:Number;
				var w:Number = PI2 * _freq / 44100;
				
                _phase += w;
                if (_phase > PI2) {
                    _phase -= PI2;
                }
				
				switch (_waveTone) 
				{
					case 0:
						//正弦波
						smpl = Math.sin(_phase);
						break;
					case 1:
						//矩形波(50:50)
						smpl = (_phase < PI) ? 1 : -1;
						break;
					case 2:
						//矩形波(25:75)
						smpl = (_phase > PI/4 && _phase < PI/2) ? 1 : -1;
						break;
					case 3:
						//矩形波(12.5:87.5)
						smpl = (_phase > PI/8 && _phase < PI/4) ? 1 : -1;
						break;
					case 4:
						//三角波
						smpl = (_phase < PI) ? -2 / PI * _phase + 1 : 2 / PI * _phase - 3;
						break;
					case 5:
						//ファミコンっぽい三角波(高音だと周波数が多すぎて波形が潰れるからこの処理が意味を成さないっぽい)
						var temp:Number = 1 / 16;
						smpl = (_phase <= PI) ? Math.floor((-2 / PI * _phase + 1)/temp)*temp : Math.floor((2 / PI * _phase - 3)/temp)*temp;
						break;
					case 6:
						//のこぎり波
						smpl = - _phase / PI + 1;
						break;
					case 7:
						//ノイズ(長周期)
						_noiseCnt++;
						if (_noiseCnt >= _noiseCntMax) {
							smpl = Math.random() * 2 - 1;
							shortNoiseFreq = smpl;
							_noiseCnt = 0;
						}
						break;
					case 8:
						//ノイズ(短周期)
						_noiseCnt++;
						if (_noiseCnt >= _noiseCntMax) {
							smpl = Math.random() * 2 - 1;
							shortNoiseFreq = smpl;
							_noiseCnt = 0;
						}
						else smpl = shortNoiseFreq;
						
						break;
				}
				
				if (smpl >= 1) smpl = 1;
				else if (smpl <= -1) smpl = -1;

				//smpl *= _volume;

                e.data.writeFloat(smpl);
                e.data.writeFloat(smpl);
            }
		}
		
		
		
	}
	

}



import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.FontStyle;
import flash.text.TextFormatAlign;
import flash.utils.Timer;

class settingWindow extends Sprite {
	private var _flag:Boolean = true;
	private var _volumeChangeFlag:Boolean = false;
	
	private var _window1:Sprite = new Sprite();
	private var _window1Width:Number = 200;
	private var _window1Height:Number = 50;
	private var _closeBtn:Sprite = new Sprite();
	private var _volumeMeter:Sprite = new Sprite();
	
	private var _window2:Sprite = new Sprite();
	private var _window2Width:Number = 200;
	private var _window2Height:Number = 400;
	
	private var tF_normal:TextFormat = new TextFormat(null, 13, 0x66FF66, null , null, null, null, null, TextFormatAlign.LEFT);;
	private var tF_hover:TextFormat = new TextFormat(null, 16, 0xAAFFAA, null, null, null, null, null, TextFormatAlign.LEFT);
	
	private var _timer:Timer = new Timer(33);
	
	public function settingWindow() {
		
		//ウィンドウが閉じてる状態の描画
		_window1.graphics.beginFill(0x000000);
		_window1.graphics.lineStyle(2, 0x66FF66);
		_window1.graphics.drawRoundRect(0, 0, _window1Width, _window1Height, 15);
		_window1.graphics.endFill();
		_window1.y = -_window1.height / 2;
		
		var _window1Txt:TextField = new TextField();
		
		_window1Txt.defaultTextFormat = new TextFormat(null, 15, 0x66FF66, FontStyle.BOLD, null, null, null, null,TextFormatAlign.CENTER);
		_window1Txt.width = _window1Width;
		_window1Txt.height = 20;
		_window1Txt.multiline = false;
		_window1Txt.selectable = false;
		
		_window1Txt.y = _window1Height / 2;
		_window1Txt.text = "Setting";
		_window1.addChild(_window1Txt);
		
		_window1.alpha = .4;
		_window1.buttonMode = true;
		_window1.mouseChildren = false;
		_window1.name = "window1";
		_window1.visible = false;
		_window1.addEventListener(MouseEvent.ROLL_OVER, onMouseRollOver);
		_window1.addEventListener(MouseEvent.ROLL_OUT, onMouseRollOut);
		_window1.addEventListener(MouseEvent.CLICK, onMouseClick);
		this.addChild(_window1);
		
		//ウィンドウが開いてる状態のときの描画
		_window2.graphics.beginFill(0x000000,.5);
		_window2.graphics.lineStyle(2, 0x66FF66);
		_window2.graphics.drawRoundRect(0, 0, _window2Width, _window2Height, 15);
		_window2.graphics.endFill();
		//_window2.y = -_window2Height - 30;
		_window2.y = -30;
		var textMenu1:TextField = new TextField();
		textMenu1.defaultTextFormat = new TextFormat(null, 20, 0x66FF66, FontStyle.BOLD);
		textMenu1.text = "Setting(Tone)";
		textMenu1.selectable = false;
		textMenu1.autoSize = TextFieldAutoSize.LEFT;
		textMenu1.x = 5;
		textMenu1.y = 30;
		_window2.addChild(textMenu1);
		
		var menuIndent:Number = 15;
		menuCreate(_window2, Main._waveToneArray[0], menuIndent, 60,0);
		menuCreate(_window2, Main._waveToneArray[1], menuIndent, 80,1);
		menuCreate(_window2, Main._waveToneArray[2], menuIndent, 100,2);
		menuCreate(_window2, Main._waveToneArray[3], menuIndent, 120,3);
		menuCreate(_window2, Main._waveToneArray[4], menuIndent, 140,4);
		menuCreate(_window2, Main._waveToneArray[5], menuIndent, 160,5);
		menuCreate(_window2, Main._waveToneArray[6], menuIndent, 180,6);
		menuCreate(_window2, Main._waveToneArray[7], menuIndent, 200,7);
		menuCreate(_window2, Main._waveToneArray[8], menuIndent, 220,8);
		
		//ボリュームメーター
		var volumeMeterTxt:TextField = new TextField();
		volumeMeterTxt.defaultTextFormat = new TextFormat(null, 20, 0x66FF66, FontStyle.BOLD);
		volumeMeterTxt.text = "Setting (Volume)";
		volumeMeterTxt.x = 5;
		volumeMeterTxt.y = 250;
		volumeMeterTxt.autoSize = TextFieldAutoSize.LEFT;
		volumeMeterTxt.selectable = false;
		_window2.addChild(volumeMeterTxt);
		
		var volumeMeterFrame:Sprite = new Sprite();
		_volumeMeter.graphics.beginFill(0x66FF66);
		_volumeMeter.graphics.drawRect(0, 0, 180, 10);
		_volumeMeter.graphics.endFill();
		_volumeMeter.buttonMode = true;
		
		_window2.addChild(_volumeMeter);
		
		volumeMeterFrame.graphics.lineStyle(1, 0x66FF66);
		volumeMeterFrame.graphics.beginFill(0x000000, 0);
		volumeMeterFrame.graphics.drawRect(0, 0, 180, 10);
		volumeMeterFrame.graphics.endFill();
		
		volumeMeterFrame.addEventListener(MouseEvent.MOUSE_DOWN, volumeChangeStart);
		volumeMeterFrame.addEventListener(MouseEvent.MOUSE_MOVE, volumeChange);
		volumeMeterFrame.addEventListener(MouseEvent.MOUSE_UP, volumeChangeEnd);
		_window2.addChild(volumeMeterFrame);
		
		volumeMeterFrame.x = _volumeMeter.x = 10;
		volumeMeterFrame.y = _volumeMeter.y = 280;
		_volumeMeter.scaleX = Main._volume;
		volumeChange();
		
		
		_window2.alpha = 1;
		_window2.visible = true;
		_window2.name = "window2";
		addChild(_window2);
		
		//閉じるボタン描画
		var btnWidth:Number = 20;
		_closeBtn.graphics.beginFill(0x000000, 0);
		_closeBtn.graphics.lineStyle(1, 0xFF0000);
		_closeBtn.graphics.lineTo(btnWidth, 0);
		_closeBtn.graphics.lineTo(btnWidth, btnWidth);
		_closeBtn.graphics.lineTo(0, btnWidth);
		_closeBtn.graphics.lineTo(0, 0);
		_closeBtn.graphics.lineTo(btnWidth, btnWidth);
		_closeBtn.graphics.moveTo(btnWidth, 0);
		_closeBtn.graphics.lineTo(0, btnWidth);
		_closeBtn.graphics.endFill();
		_closeBtn.x = 170;
		_closeBtn.y = 35;
		_closeBtn.name = "closeBtn";
		_closeBtn.buttonMode = true;
		_closeBtn.mouseChildren = false;
		_closeBtn.addEventListener(MouseEvent.CLICK, onMouseClick);
		_window2.addChild(_closeBtn);
		_timer.addEventListener(TimerEvent.TIMER, onTimerEvent);
	}
	
	private function volumeChangeStart(e:MouseEvent):void 
	{
		_volumeChangeFlag = true;
		volumeChange();
	}
	
	private function volumeChange(e:MouseEvent = null):void 
	{
		if (_volumeChangeFlag == true) {
			var pt:Point = localToGlobal(new Point(_volumeMeter.x, _volumeMeter.y));
			_volumeMeter.scaleX = (stage.mouseX - pt.x) / 180;
			if (_volumeMeter.scaleX < 0) _volumeMeter.scaleX = 0;
			else if (_volumeMeter.scaleX > 1) _volumeMeter.scaleX = 1;
			Main._volume = _volumeMeter.scaleX;
			Main._soundCh.soundTransform = new flash.media.SoundTransform(_volumeMeter.scaleX);
		}
		
	}
	
	private function volumeChangeEnd(e:MouseEvent):void 
	{
		_volumeChangeFlag = false;
	}
	
	private function menuCreate(baseSp:Sprite,name:String,tx:Number,ty:Number,num:uint):void
	{
		var sp:Sprite = new Sprite();
		sp.buttonMode = true;
		sp.mouseChildren = false;
		sp.name = num.toString();
		var tf:TextField = new TextField();
		tf.name = "txt";
		tf.text = name;
		tf.width = baseSp.width;
		tf.height = 25;
		tf.x = tx;
		tf.y = ty;
		tf.selectable = false;
		tf.setTextFormat(tF_normal);
		sp.addChild(tf);
		baseSp.addChild(sp);
		
		sp.addEventListener(MouseEvent.ROLL_OVER, onMouseRollOver);
		sp.addEventListener(MouseEvent.ROLL_OUT, onMouseRollOut);
		sp.addEventListener(MouseEvent.CLICK, onMouseClick);
	}
	
	private function onTimerEvent(e:TimerEvent = null):void 
	{
		if (_flag) {
			_window2.y += 50;
			if (_window2.y >= -30) {
				_timer.stop();
			}
		} else {
			_window2.y -= 50;
			if (_window2.y <= - _window2.height) {
				_timer.stop();
				_window1.visible = true;
				_window2.visible = false;
			}
		}
	}
	
	private function onMouseClick(e:MouseEvent):void 
	{
		if (e.target.name == "window1") {
			_flag = true;
			_window2.visible = true;
			_window1.visible = false;
			onTimerEvent(null);
			_timer.start();
		} if (e.target.name == "closeBtn") {
			_flag = false;
			onTimerEvent(null);
			_timer.start();
		} else {
			Main._waveTone = e.target.name;
			Main.toneTextChange();
		}
	}
	
	private function onMouseRollOut(e:MouseEvent):void 
	{
		if (e.target.name == "window1") {
			e.target.alpha = .4;
		} else {
			var txtInstance:TextField = e.target.getChildByName("txt");
			txtInstance.setTextFormat(tF_normal);
		}
	}
	
	private function onMouseRollOver(e:MouseEvent):void 
	{
		if (e.target.name == "window1") {
			e.target.alpha = 1;
		} else {
			var txtInstance:TextField = e.target.getChildByName("txt");
			txtInstance.setTextFormat(tF_hover);
		}
	}
	
	
}