|
-
sound problems with in custom sound class
im trying to make an Audio control Class... the class is working fine until i get to the add sound part..
i have two buttons, on and off.. when the movie loads, a looping background sound is playing, hitting off button will stop all sounds, the looping sound as well as the rollOver and Hit sounds...
how do i do this in my class code..
thanks
class SoundToggle extends Sound {
private var btnArray:Array;
private var lastClicked:MovieClip;
private var curBtn:MovieClip;
private var soundActive = true;
function SoundToggle(holder:MovieClip, btnLinkage:String, soundArray:Array, xSpace:Number, mySound:Sound, loopSound:Sound) {
//trace("soundToggle class instantiated");
// Init button array to keep track of all the buttons
btnArray = new Array();
//loopSoundToggle(true, "loopSound");
//_level0.mySound.attachSound("loopSound");
//_level0.mySound.start();
for (var i:Number = 0; i < soundArray.length; i++) {
// Attach button clip
var btn:MovieClip = holder.attachMovie(btnLinkage, "btn_" + i, holder.getNextHighestDepth());
//trace("btn" + btn);
// Store button's destination label
btn.myDest = soundArray[i];
// Set button text
setBtnText(btn, btn.myDest);
// Position button
positionBtn(btn, btn._width * i + xSpace * i);
// Position button on Stage
positionBtnStage(btn, (btn._width * i + xSpace * i + Stage.width / 2) - btn._width / 2, (Stage.height / 2) - btn._height / 2);
// Init button behaviour
initBtn(btn);
// Store a reference to the button to keep track of all the buttons
btnArray.push(btn);
}
}
private function setBtnText(btn:MovieClip, labelTxt:String) {
// Sets button label text
btn.labelTxtHolder.labelTxt.text = labelTxt;
}
private function positionBtn(btn:MovieClip, myXPos:Number) {
btn._x = myXPos;
}
private function positionBtnStage(btn:MovieClip, xPos, yPos) {
btn._x = xPos;
btn._y = yPos;
}
private function initBtn(btn:MovieClip, mySound:Sound, loopSound:Sound) {
// Initializes button behaviour
var thisClass = this;
// Sets On Button
for (var i:Number = 0; i < btnArray.length; i++) {
var theBtn:MovieClip = btnArray[i];
curBtn = btnArray[0];
//trace("curBtn " + btnArray[0]);
if (i == 0) {
curBtn.select = true;
lastClicked = curBtn;
curBtn.gotoAndStop("released");
curBtn.enabled = false;
} else {
curBtn.over = false;
curBtn.select = false;
}
}
btn.onRollOver = function() {
this.gotoAndPlay("rollOver");
//_level0.mySound.attachSound("rollOver");
//_level0.mySound.start();
}
btn.onRollOut = function() {
this.gotoAndPlay("rollOut");
}
btn.onRelease = btn.onReleaseOutside = function() {
_level0.playSounds("hit");
//_level0.mySound.attachSound("hit");
//_level0.mySound.start();
thisClass.lastClicked.gotoAndPlay("rollOut");
thisClass.lastClicked.enabled = true;
thisClass.lastClicked = this;
this.enabled = false;
trace(this + " this");
if (thisClass.lastClicked == _level0.btn_1) {
trace("sounds are off");
_level0.soundActive = false;
_level0.loopSound.stop();
} else {
trace("sounds are on");
if (soundActive) {
_level0.loopSound.start(0, 1000);
}
}
}
}
public function toggleBtns(val:Boolean) {
// Loops through button array & toggles each button
for (var i:Number = 0; i < btnArray.length; i++) {
var theBtn:MovieClip = btnArray[i];
// Ignore the currently selected button, it should always be disabled
if (theBtn !== lastClicked) {
theBtn.enabled = val;
}
}
}
public function playSounds(whichSound:String) {
if (soundActive) {
_level0.mySound.attachSound(whichSound);
_level0.mySound.start();
}
}
public function loopSoundToggle(val:Boolean) {
if (soundActive) {
_level0.loopSound.attachSound("loopSound");
_level0.loopSound.start();
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|