forked from: soundtest10 - SOUNDRAIN
forked from soundtest10 - SOUNDRAIN (diff: 31)
sound by @AlainMikuni [SWF(width="465",height="465",backgroundColor="0x000000",frameRate="60")]
ActionScript3 source code
/**
* Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5Gce
*/
package
{
/**
sound by @AlainMikuni
**/
import flash.display.Shape;
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;
//[SWF(width="465",height="465",backgroundColor="0x000000",frameRate="60")]
[SWF(width="465",height="465",backgroundColor="0xffffff",frameRate="60")]
public class Soundtest10 extends Sprite
{
private var snd:Sound;
private var sndChannel:SoundChannel;
private var arr:Array = [];
public function Soundtest10():void
{
//graphics.beginFill(0x000000);
//graphics.drawRect(0, 0, 465, 465);
//graphics.endFill();
playSound("http://www.takasumi-nagai.com/soundfiles/sound005.mp3");
}
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);
snd.addEventListener(Event.COMPLETE, onComp);
}
private function onComp(e:Event):void
{
arr = draw();
sndChannel=new SoundChannel();
sndChannel = snd.play(0, 10);
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(event:Event):void
{
var bytes:ByteArray = new ByteArray();
SoundMixer.computeSpectrum(bytes, false, 0);
for (var i:int = 0; i < 512; i++)
{
var sp:Sprite = arr[i] as Sprite;
var data:Number = bytes.readFloat();
sp.alpha = data;
sp.scaleX = data;
}
}
private function draw():Array
{
var master_arr:Array = [];
for (var i:int = 0; i < 32; i++)
{
for (var j:int = 0; j < 16; j++)
{
var _num:int = Math.round(Math.random() * 1);
var sp:Sprite = new Sprite();
var _width:Number = stage.stageWidth / 32;
var _height:Number = stage.stageHeight / 16;
sp.graphics.beginFill(0);
sp.graphics.drawRect(0,0,_width/3,_height);
sp.graphics.endFill();
sp.x = _width * i + _width/3+2*2*Math.random();
sp.y = _height * j;
addChild(sp);
master_arr.push(sp);
}
}
var frames:Sprite = addChild(new Sprite) as Sprite;
for ( i = 0; i < 32; i++)
{
for ( j = 0; j < 16; j++)
{
_num = Math.round(Math.random() * 1);
var shp:Shape= new Shape();
_width = stage.stageWidth / 32;
_height = stage.stageHeight / 16;
shp.graphics.lineStyle(0);
shp.graphics.drawRect(0,0,_width/3,_height);
shp.graphics.endFill();
shp.x = _width * i + _width/3+2*2*Math.random();
shp.y = _height * j;
frames.addChild(shp);
}
}
return master_arr;
}
}
}