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

soundtest3

license : 詳細ActionScript3.0 2 by 大重美幸 p196-197
にZを加えたら楽しかった。
Get Adobe Flash player
by gaina 06 Mar 2010
package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundLoaderContext;
	import flash.media.SoundMixer;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	import flash.system.LoaderContext;
	
	/**
	 * license : 詳細ActionScript3.0 2 by 大重美幸 p196-197
	 * にZを加えたら楽しかった。
	 */
	[SWF(width=465,height=465,backgroundColor=0x000000)]
	public class soundGrid extends Sprite
	{
		private var leftRightSpList:Array;
		private var snd:Sound;
		private var stageSp:Sprite;
		private var stageSp02:Sprite;
		
		function soundGrid() 
		{
			stageSp = new Sprite();
			addChild(stageSp);
			stageSp02 = new Sprite();
			addChild(stageSp02);
			
			stageSp.x = 0;
			stageSp.y = 50;
			stageSp02.x = 0;
			stageSp02.y = stage.stageHeight - 50;
			
			leftRightSpList = makeLeftRightSpList();
			
			playSound("http://www.takasumi-nagai.com/soundfiles/01.mp3");
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function playSound(sndUrl:String):void
		{
			snd = new Sound();
			var context:SoundLoaderContext = new SoundLoaderContext(10,true);
			var req:URLRequest = new URLRequest(sndUrl);
			snd.load(req,context);
			var sndChannel:SoundChannel;
			sndChannel = snd.play(0,int.MAX_VALUE);
			
		}
		
		private function onEnterFrame(event:Event):void {			
			var _sp:Sprite;
			var bytes:ByteArray = new ByteArray();
			SoundMixer.computeSpectrum(bytes, false, 0);
			var i:uint, j:uint;
			for (i = 0; i < 2; i++)
			{
				var spList:Array = leftRightSpList[i];
				for (j = 0; j < 256; j++)
				{
					_sp = spList[j];
					var rf:Number = bytes.readFloat();
					var scale:Number = Math.max(0.05, 1 + rf * 40);
					if (i == 0) {
						_sp.y = scale * 5;
						_sp.z = scale * 10;
						_sp.scaleX = _sp.scaleY = scale;
					}else {
						_sp.y = scale * -5;
						_sp.z = scale * 10;
					}				
				}
			}
		}
		
		private function makeLeftRightSpList():Array
		{
			var spLRList:Array = new Array();
			var grid_size:Number = 15;
			var circle_r:uint = 2;
			var n:uint;
			var i:Number;
			
			for (n = 0; n < 2; n++)
			{
				var spList:Array = new Array();
				for (i = 0; i < 256; i++)
				{
					var sp:Sprite = new Sprite();
					sp.graphics.beginFill(0xFF0000);
					sp.graphics.drawCircle(0, 0, circle_r);
					sp.graphics.endFill();
					sp.x = stage.stageWidth/256*i;
					if (n == 0) {
						stageSp.addChild(sp);
					}else {
						stageSp02.addChild(sp);
					}
					spList.push(sp);
					
				}
				spLRList.push(spList);
			}
			return spLRList;
		}
		
	}

}