我正在为一个项目构建一个样品垫类型的仪器,我有四个通道用于四个不同的仪器,界面有四个按钮来选择仪器,当选择按钮时图像应该是绿色但是当选择另一个仪器时它应该转到影片剪辑的第二帧,这是一个红色按钮,表示仪器已关闭。
第23行我添加了一个与其不会吐出任何错误的频道关联的变量的条件状态但当我点击另一个按钮时也不会改变图像任何人都知道我哪里出错了
//import flash stuff
import flash.events.MouseEvent;
import flash.display.MovieClip;
stop();
//event listener for the power button
poweroff.addEventListener(MouseEvent.CLICK, mouseClick1);
function mouseClick1(event:MouseEvent):void{
gotoAndStop(1);
}
//select which samples to use with event listener,
//changes var selector bellow, so input listens for
//different samples
drumSelector.addEventListener(MouseEvent.CLICK, drumClick);
function drumClick(event:MouseEvent):void{
selector = drums;
if (selector == drums)
{
drumSelector.gotoAndStop(1);
}else{
drumSelector.gotoAndStop(2);
}
}
bassSelector.addEventListener(MouseEvent.CLICK, bassClick);
function bassClick(event:MouseEvent):void{
selector = bass;
}
synthSelector.addEventListener(MouseEvent.CLICK, synthClick);
function synthClick(event:MouseEvent):void{
selector = synth;
}
beatSelector.addEventListener(MouseEvent.CLICK, beatClick);
function beatClick(event:MouseEvent):void{
selector = beat;
}
//selects which movieclip samples to use for input
var selector:MovieClip = drums;
//listen for events on display keyboard
//make movieclips visible so they can play samples
key1.addEventListener(MouseEvent.CLICK, key1Click);
function key1Click(evt:MouseEvent):void
{
selector.i1.visible=true;
}
key2.addEventListener(MouseEvent.CLICK, key2Click);
function key2Click(evt:MouseEvent):void
{
selector.i2.visible=true;
}
key3.addEventListener(MouseEvent.CLICK, key3Click);
function key3Click(evt:MouseEvent):void
{
selector.i3.visible=true;
}
key4.addEventListener(MouseEvent.CLICK, key4Click);
function key4Click(evt:MouseEvent):void
{
selector.i4.visible=true;
}
答案 0 :(得分:0)
此时您的条件仅在您单击drumSelector按钮时执行,因为它位于drumSelector单击处理程序内。您应该将条件移动到一个单独的函数中,并从控制仪器的四个按钮中的每个按钮的单击处理程序中调用它。
答案 1 :(得分:0)
为条件创建一个新函数,如:
function updateSelector(){
if (selector == drums)
{
drumSelector.gotoAndStop(1);
}else{
drumSelector.gotoAndStop(2);
}
}
然后在每个按钮处理程序中:
bassSelector.addEventListener(MouseEvent.CLICK, bassClick);
function bassClick(event:MouseEvent):void{
selector = bass;
updateSelector();
}