Right now I’m in the process of building a drum machine in Flash. The interface is based off of combo boxes and data that I load into the combo boxes. Depending on what you choose in the combo box, a sound should play at a certain interval. I have that part working perfectly. When you click the element of the combo box, the sound plays, and my set interval function calls.
Now the problem I am having is actually clearing the setInterval everytime you change the element in the combo box. I am using a listener set up to find when the combo box changes, I know it has something to do with when I clear the interval, but for the life of me I can’t figure out how to clear it when the listener is called. If anyone could help me it would be very much appreciated!!! :cowboy:
Here is the listener function I am using to call setInterval:
dbListener1.change = function (evt_obj:Object) { //create event handler function
isDBactive = true;
//trace("Currently selected item is: " + evt_obj.target.selectedItem.label);
// playSound(evt_obj.target.selectedItem.data);
//this.onEnterFrame = function(){
clearInterval(dbInt1);
if(isDBactive == true){
trace("db is true");
var dbInt1 = setInterval(playSound,1000,evt_obj.target.selectedItem.data);
//}
}
}
Well I just tried something, that really shouldn’t have worked, but did, I put
var dbInt1 = 0;
outside of the listener, and then took away the ‘var’, from in front of dbInt1 = setInterval… and it works perfectly. It seems like a really weird way to do that though, and doesn’t seem like it would be in good coding practice to do that. Anyone have any points of how to make that work in a different way than I did it?