下面我有一个名为buttonClickResult的函数,当用户单击图像时会启动该函数。我希望单击打开/关闭以在两个值之间重新分配名为distortionSwitch的变量。一种称为emptyCable,另一种称为overdrive。此变量位于名为bufferFunctionName的函数内
我不太清楚如何将此变量赋值传递给另一个函数。
总而言之,当用户单击按钮时,bufferFunctionName 中 名为distortionSwitch的变量应在名为emptyCable的变量赋值和名为overdrive的变量赋值之间切换
谢谢你。
var humSnd = new Audio('audio/hum.wav');
var button = document.getElementById('btn1');
buttonClickResult = function () {
function playClickSound(filename) {
var snd = new Audio(filename);
snd.play();
}
button.onmousedown = function buttonClicked() {
if (button.className == "off") {
button.className = "on";
button.src = 'imgs/on.png';
playClickSound('audio/click.wav');
humSnd.play();
humSnd.loop = true;
} else if (button.className == "on") {
button.className = "off";
button.src = 'imgs/off.png';
playClickSound('audio/click.wav');
humSnd.pause();
}
}
};
buttonClickResult();
var context = new webkitAudioContext();
// Start Of Web Audio API Buffer & Playback Abstraction
function audioApiKey(domNode, fileDirectory, bufferFunctionName, incomingBuffer, savedBuffer, xhr) {
this.domNode = domNode;
this.fileDirectory = fileDirectory;
this.bufferFunctionName = bufferFunctionName;
this.incomingBuffer = incomingBuffer;
this.savedBuffer = savedBuffer;
this.xhr = xhr;
bufferFunctionName = function () {
var distortionSwitch = overdrive; // THIS SHOULD TOGGLE
var source = context.createBufferSource();
source.buffer = savedBuffer;
source.connect(distortionSwitch.input);
distortionSwitch.connect(delay.input);
delay.connect(convolver.input);
convolver.connect(context.destination);
source.noteOn(0); // Play sound immediately
};
附录 当我在 bufferFunctionName 下面编写代码时,即使它的范围以它应该的方式(我认为?)
var distortionSwitch = overdrive;
bufferFunctionName = function () {
var source = context.createBufferSource();
source.buffer = savedBuffer;
source.connect(distortionSwitch.input);
distortionSwitch.connect(delay.input);
delay.connect(convolver.input);
convolver.connect(context.destination);
source.noteOn(0); // Play sound immediately
};
当我这样写它时,它工作正常
bufferFunctionName = function () {
var distortionSwitch = overdrive;
var source = context.createBufferSource();
source.buffer = savedBuffer;
source.connect(distortionSwitch.input);
distortionSwitch.connect(delay.input);
delay.connect(convolver.input);
convolver.connect(context.destination);
source.noteOn(0); // Play sound immediately
};