//扩展Sound对象的方法
Sound.prototype.fade = function (fadeType, fadeDuration) {
this.fadeDuration = (fadeDuration * 1000) / 100;
this.fadeType = fadeType;
this.currentVolume = this.getVolume ();
this.intID = setInterval (function (thisObj) {
thisObj.doFade (thisObj.fadeType);
}, this.fadeDuration, this);
this.doFade = function (fadeType) {
if (fadeType == "out") { //Sound 淡出
this.setVolume (this.currentVolume--);
if (this.getVolume () <= 0) {
this.onFadeComplete ();
clearInterval (this.intID);
}
}
else if (fadetype == "in") { //Sound 淡入
this.setVolume (this.currentVolume++);
if (this.getVolume () >= 100) {
this.onFadeComplete ();
clearInterval (this.intID);
}
}
};
};
okApp = function () {
trace ("oh yes!");
};
controlBtn.labels.text = "play";
//新建Sound对象并邦定库里的声音文件
mySound = new Sound ();
mySound.attachSound ("soundLoop");
mySound.onFadeComplete = okApp;
//按钮控制
controlBtn.onRelease = function () {
if (click == null) {
mysound.start ();
mySound.fade ("in", 2);
click = "";
controlBtn.labels.text = "stop";
}
else {
mySound.fade ("out", 2);
click = null;
controlBtn.labels.text = "play";
}
};