学习网站建设,网页知识,电脑技巧,AS3代码,FLASH效果,课件制作,网络学习,运动生活,心情日志博客
2010年02月26日AS3 学习

0 条评论

FLASH声波频谱练习

FLASH声波频谱练习,详见《as3详细编程》,as3代码如下:

const PLOT_HEIGHT:int=200;//图上标出高,常量值通常采用大写
const CHANNEL_LENGTH:int=256;//通道长度
var snd:Sound=new Sound();
var req:URLRequest=new URLRequest("http://bbs.fhsx.cn/uploadfile/2006-6/200662185034809.mp3");
snd.load(req);
var channel:SoundChannel;
channel=snd.play();
//this.filters=[new GlowFilter(0xffffff,15,15)];
addEventListener(Event.ENTER_FRAME,onEnterFrame);
//snd.addEventListener(Event.SOUND_COMPLETE,onPlaybackComplete);

var bytes:ByteArray=new ByteArray();
function onEnterFrame(event:Event) {
SoundMixer.computeSpectrum(bytes,false,0);
var g:Graphics=this.graphics;
g.clear();
g.lineStyle(0,0x6600cc);
g.beginFill(0x6600cc,0.5);//如果不是封闭图形,会自动封口
g.moveTo(0,PLOT_HEIGHT);
var n:Number=0;
//////////////左//////////////
for (var i:int=0; i<CHANNEL_LENGTH; i++) {
n=bytes.readFloat()*PLOT_HEIGHT;
g.lineTo(i*2,PLOT_HEIGHT-n);
}
g.lineTo(CHANNEL_LENGTH*2,PLOT_HEIGHT);
g.endFill();
////////////////右/////////////////
g.lineStyle(0,0xcc0066);
g.beginFill(0xcc0066,0.5);
g.moveTo(CHANNEL_LENGTH*2,PLOT_HEIGHT);
for (i=CHANNEL_LENGTH; i>0; i--) {
n=bytes.readFloat()*PLOT_HEIGHT;
g.lineTo(i*2,PLOT_HEIGHT-n);
}
g.lineTo(0,PLOT_HEIGHT);
g.endFill();
}
function onPlaybackComplete(event:Event) {
removeEventListener(Event.ENTER_FRAME,onEnterFrame);
}

本文地址:http://www.lxlong.net/archives/645.html

本文标题:FLASH声波频谱练习

 
« »                

没有评论

发表评论 »