code:
var mySound = new Sound(this); // create a new sound object
mySound.attachSound("bgm"); // associate it with the your sound file
function fade() {
this._alpha += (this.dest - this._alpha) / this.ease;
if (Math.round(this._alpha) == this.dest) {
this._alpha = this.dest;
delete this.onEnterFrame;
}
}
for (var i = 0; i < 5; ++i) {
this["red" + i].dest = 100;
this["red" + i].ease = 1;
this["btn" + i].id = i;
this["btn" + i].onPress = function() {
var mc = this._parent["red" + this.id];
if (mc.dest == 100) {
mc.dest = 0;
mc.ease = 1;
} else {
mc.dest = 100;
mc.ease = 5;
this._parent.mySound.start(0, 1); // play the sound
}
mc.onEnterFrame = fade;
};
}