soundtest4
...
@author gaina
/**
* Copyright gaina ( http://wonderfl.net/user/gaina )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fWwu
*/
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.utils.ByteArray;
/**
* ...
* @author gaina
*/
[SWF(width=465,height=465)]
public class Rectangle extends Sprite
{
private var rect:Sprite;
private var spArray:Array = [];
private var containerArray:Array = [];
private var snd:Sound;
private var wSize:Number;
private var vSize:Number;
public function Rectangle()
{
wSize = stage.stageWidth / 32;
vSize = stage.stageHeight / 16;
containerArray = rectDraw();
playSound('http://www.takasumi-nagai.com/soundfiles/01.mp3');
addEventListener(Event.ENTER_FRAME, onEnter);
}
private function playSound(url:String):void
{
snd = new Sound();
var context:SoundLoaderContext = new SoundLoaderContext(0, true);
var sndReq:URLRequest = new URLRequest(url);
snd.load(sndReq,context);
var sndCh:SoundChannel = new SoundChannel();
sndCh = snd.play(0, 5);
}
private function onEnter(event:Event):void
{
var sp:Sprite = new Sprite();
var byte:ByteArray = new ByteArray();
SoundMixer.computeSpectrum(byte, false, 0);
var i:int;
for (i = 0; i < 512; i++) {
sp = containerArray[i];
var rl:Number = byte.readFloat();
sp.z = rl * 100;
sp.alpha = 0.2;
//sp.y += 2;
//sp.x += 1;
//if (sp.y > stage.stageHeight-vSize) {
// sp.y = 0 - vSize;
//}
//if (sp.x > stage.stageWidth-wSize) {
// sp.x = 0 - wSize;
//}
}
}
private function rectDraw():Array
{
var i:int, j:int;
for (i = 0; i < 16; i++) {
for (j = 0; j < 32; j++) {
rect = new Sprite();
rect.graphics.clear();
rect.graphics.lineStyle(0);
rect.graphics.drawRect(0, 0, wSize, vSize);
rect.x = j * wSize;
rect.y = i * vSize;
rect.z = 0;
addChild(rect);
spArray.push(rect);
}
}
return spArray;
}
}
}