简单说一下做法,具体看我的源文件。
1.导入四个音乐文件,在库中右键-链接,标识符分别为:s01 s02 s03 s04
2.做一音量控件,点击控件加AS:
on (press) {
startDrag(this, true, left, top, right, bottom);
}
on (release) {
stopDrag();
}
onClipEvent (load) {
top = _y;
bottom = _y;
left = _x;
right = _x+150;
_x += 75;
}
onClipEvent (enterFrame) {
_root.mySound.setVolume(_x-left);
} 3.音频视觉效果
做一个绿色的长方形,F8转为影片,实体名称为:line
第一帧加AS:
_root.lineMc.line._visible = false;
_root.lineMc.onEnterFrame = function() {
for (var i = 0; i<20; i++) {
duplicateMovieClip("line", "line"+i, i);
with (_root.lineMc["line"+i]) {
_x += 4*i;
_y = 0;
_yscale = Math.round(Math.random()*100);
}
}
};
stop(); 第二帧加AS:
_root.lineMc.line._visible = false;
_root.lineMc.onEnterFrame = function() {
for (var i = 0; i<20; i++) {
duplicateMovieClip("line", "line"+i, i);
with (_root.lineMc["line"+i]) {
_x += 4*i;
_y = 0;
_yscale = 25;
}
}
};
stop(); 4.把各个配件安放好,控制音乐的按钮实体名称为:btnPrev btnPlay btnPause btnNext
第三步做的音频视觉效果控件的实体名称为:lineMc
拉三个动态文本,变量分别为:pauseTotalTime soundName txtBtn
在第一帧加AS:
i = 1;//初始值
s1 = "吻别的位置-李克勤";
s2 = "phone杀令-陈慧琳";
s3 = "世上只有-容祖儿";
s4 = "越吻越伤心-张学友";
mySound = new Sound();//创建 Sound 对象
mySound.attachSound("s01");//调用库中链接标识符为s01的声音文件
mySound.start();//开始播放
mySound.onSoundComplete = function() {//自动调用
i++;
if (i>4) {
i = 1;
}
mySound.attachSound("s0"+i);
mySound.start();
};
onEnterFrame = function () {
pauseTimes = Math.round(mySound.position/1000);//声音文件已播放时间
totalTimes = Math.round(mySound.duration/1000);//声音文件总时间
pauseTotalTime = pauseTimes+"s"+"/"+totalTimes+"s";
soundName = eval("s"+i);//模拟数组
trace(pauseTotalTime);
trace(i);
};
var song = true;//声明一个变量,song为true,即声音文件正在播放
btnPlay.onRelease = function() {
if (song == false) {
mySound.start(pauseTimes);//从暂停秒数开始播放
song = true;
}
_root.lineMc.gotoAndStop(1);
};
btnPause.onRelease = function() {
if (song == true) {
pauseTimes = Math.round(mySound.position/1000);
mySound.stop();//暂停播放
song = false;
}
_root.lineMc.gotoAndStop(2);
};
btnNext.onRelease = function() {
i++;
if (i>4) {
i = 1;
}
mySound.stop();
mySound.attachSound("s0"+i);
mySound.start();
_root.lineMc.gotoAndStop(1);
};
btnPrev.onRelease = function() {
i--;
if (i<1) {
i = 4;
}
mySound.stop();
mySound.attachSound("s0"+i);
mySound.start();
_root.lineMc.gotoAndStop(1);
};
btnPrev.onRollOver = function() {
_root.txtBtn = "上一首";
};
btnPlay.onRollOver = function() {
_root.txtBtn = "播放";
};
btnPause.onRollOver = function() {
_root.txtBtn = "暂停";
};
btnNext.onRollOver = function() {
_root.txtBtn = "下一首";
};
btnPrev.onRollOut = function() {
_root.txtBtn = "";
};
btnPlay.onRollOut = function() {
_root.txtBtn = "";
};
btnPause.onRollOut = function() {
_root.txtBtn = "";
};
btnNext.onRollOut = function() {
_root.txtBtn = "";
};
如果觉得文件太大,可将attachSound改为loadSound,加载外部音乐文件,代码作部分修改,原理一样的。
由于文件超标,源文件删掉音乐文件。打开源文件后,导入四个声音文件,加上链接标识符。原文件:
点击这里下载源文件