问题 代码第一次运行时,它可以正常回答正确的答案。然而,除非您选择与第一个答案相同的值,否则一切都会出错。该值在比较输入值和答案的函数之前发生变化,但不会恢复到它的值。
代码:
var eventCount : Number = 1;
function intervalTraining()
{
//sounds
//first note
var randomSound1High : int = 12;
var randomSound1Low : int = 77;
var randomSound1 : int = Math.floor(Math.random()*(1+randomSound1High-randomSound1Low))+randomSound1Low;
//second note
var randomSound2High : int = randomSound1-12;
var randomSound2Low : int = randomSound1+12;
var randomSound2 : int = Math.floor(Math.random()*(1+randomSound2High-randomSound2Low))+randomSound2Low;
trace(randomSound1, randomSound2);
//interval
var interval : int =Math.abs(randomSound1-randomSound2);
//play sounds
function playIntervals()
{
// set timer; add timer listener; start timer
var myTimer:Timer = new Timer(500, 1); myTimer.addEventListener(TimerEvent.TIMER, playInterval2); myTimer.start();
//play first interval
intervalArray[randomSound1].play(100, 1);
//play second interval
function playInterval2(event:TimerEvent):void
{
intervalArray[randomSound2].play(100, 1);
}
}
if (eventCount==1)
{
//button actions
P1.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(0);});
M2.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(2);});
M3.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(4);});
P4.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(5);});
P5.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(7);});
M6.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(9);});
M7.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(11);});
P8.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(12);});
m2.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(1);});
m3.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(3);});
TT.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(6);});
m6.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(8);});
m7.addEventListener(MouseEvent.CLICK, function(e:Event){buttonClick(10);});
}eventCount=eventCount+1;
trace("b4 function interval: "+interval)//new value is shown
function buttonClick(intervalValue:Number):void
{
trace("infuntion interval: "+interval)//resorts back to old value for some reason
if(intervalValue==interval){trace("correct");intervalTraining();}else{trace("wrong");};
}
playIntervals();
}
intervalTraining();