# How do I fix this actionscript?

**URL:** <https://forum.kirupa.com/t/how-do-i-fix-this-actionscript/310323>\
**Category:** flash\
**Created:** [June 7, 2010, 6:27pm UTC](https://forum.kirupa.com/t/how-do-i-fix-this-actionscript/310323 "2010-06-07T18:27:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Headman](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@Headman](https://forum.kirupa.com/u/Headman)\
**Post date:** [June 7, 2010, 6:27pm UTC](https://forum.kirupa.com/t/how-do-i-fix-this-actionscript/310323/1 "2010-06-07T18:27:34Z")

</div>

I have it working but the audio starts playing at the same time without clicking anything. I have 3 different audio, one for the intro. One for the correct answer, one for the incorrect. They play but not at the correct time. what did I do wrong?

> //make"col", “pe” or “sit”  
> var qType:String = “col”;

//fill out the question stem  
var questionStem:String = "\<b\>Check on Learning:\</b\> ";

//fill out distractor array 1 to 6 items; put an asterisk in front of each correct  
var questionArray:Array = new Array (“Who sang Thriller?”);

var distractorArray:Array = new Array (“Bob Hope”,  
“Madonna”,  
“Sting”,  
“\*Michael Jackson”);

var instructions:String = “Click on the best answer(s), and click the Done button.”;

//fill out the feedbacks  
var correctFeedback:String = “Outstanding! Correct Answer.”;  
var feedback1:String = “Incorrect. Please Try Again.”;  
var feedback2:String = “Incorrect. It is recommended that you review the information again.”;  
var feedback3:String = “Incorrect. It is recommended that you review the information again.”;

var continueArray:Array = new Array(" Click on Next button to continue.“,  
" Click on Next arrow to continue.”);  
var finalFeedback:Array = new Array(“”,“Incorrect. It is recommended that you review the information again.”);

var numDistractors:Number = distractorArray.length;  
var numCorrect:Number = 0;  
var maxTries:Number = 0;  
var movieId:MovieClip = this;  
var yoffset:Number = 15;  
doInitialize();  
stop();

function doInitialize () {  
instruct.instText.html = true;  
stem.stemText.html = true;  
instruct.instText.htmlText = instructions;  
instruct.instText.autoSize = true;  
stem.stemText.htmlText = questionStem;  
stem.stemText.autoSize = true;  
moveUpper();  
doDistractors ();  
moveLower();  
feedback.autoSize = true;  
reviewBtn.\_y = replayBtn.\_y;

```
if (numTries == 2) {
    reviewBtn._visible = true;
    feedback.text = "Now, try again.";
} else {
    doneBtn._visible = true;
    doActive (true);
    reviewBtn._visible = false;
    feedback.text = "";
}
replayBtn._visible = false;
showBtn._visible = false;
switch (qType) {
case "col" :
    maxTries = 4;
    break;
case "pe" :
    maxTries = 4;
    break;
case "sit" :
    maxTries = 2;
    break;
}

```

}  
function doDistractors () {  
var distractorName:MovieClip;  
var btnName:MovieClip;  
var text1:String, text2:String, outText:String;  
var len:Number;  
var distNum:Number;  
var prevDistractor:MovieClip = null;

```
for (distNum = 1; distNum &lt;= numDistractors; distNum++) {
    distractorName = distractor_mc.duplicateMovieClip ("distractor" + distNum, this.getNextHighestDepth ());
    // distractorName._y = distractor_mc._y+((distNum-1)*yoffset);
    btnName = qBtn_mc.duplicateMovieClip ("qBtn" + distNum, this.getNextHighestDepth ());
    // btnName._y = qBtn_mc._y + ((distNum-1)*yoffset);
    btnName.btnSelected = false;
    if (distNum &lt;= numDistractors) {
        text1 = distractorArray[distNum - 1];
        if (text1.indexOf ("*") == 0) {
            len = text1.length;
            text2 = text1.substr (1, len);
            outText = text2;
            btnName.correct = true;
            numCorrect++;
        } else {
            outText = text1;
            btnName.correct = false;
        }
        distractorName.distractorText.html = true;
        distractorName.distractorText.htmlText = outText;
        distractorName.distractorText.autoSize = true;
        if (prevDistractor == null) {
            prevDistractor = distractorName;
            distractorName._y = distractor_mc._y + ((distNum - 1) * yoffset);
            btnName._y = qBtn_mc._y + ((distNum - 1) * yoffset);
        } else {
            distractorName._y = prevDistractor._y + prevDistractor.distractorText._height + yoffset;
            btnName._y = prevDistractor._y + prevDistractor.distractorText._height + (yoffset - 3);
            prevDistractor = distractorName;
        }
        distractorName.onRelease = function () {
            doClick (this);
        };
        btnName.onRelease = function () {
            doClick (this);
        };
    }
}

```

}  
function doGrade () {  
var weight:Number = 1 / numCorrect;  
var score:Number = 0;  
var correct:Number = 0;  
var outText:String;  
var btnName:MovieClip;  
var numAnswered:Number = 0;  
var count:Number;  
for (count = 1; count \<= numDistractors; count++) {  
btnName = this[“qBtn” + count];  
if (btnName.btnSelected == true) {  
numAnswered++;  
}  
if (btnName.correct == true and btnName.btnSelected == true) {  
correct++;  
}  
}  
if (numAnswered \> numCorrect) {  
correct = 0;  
}  
score = weight \* correct;  
switch (numTries) {  
case 1 :  
if (score == 1) {  
outText = correctFeedback;  
numTries = maxTries;  
doneBtn.\_visible = false;  
doActive (false);  
} else {  
outText = feedback1;  
}  
if (qType == “sit”) {  
numTries = maxTries;  
}  
break;  
case 2 :  
if (score == 1) {  
numTries = maxTries;  
outText = correctFeedback;  
doneBtn.\_visible = false;  
doActive (false);  
} else {  
outText = feedback2;  
if (qType == “col”) {  
reviewBtn.\_visible = true;  
}  
}  
break;  
case 3 :  
numTries = maxTries;  
if (score == 1) {  
outText = correctFeedback;  
} else {  
outText = feedback3;  
}  
if (qType == “pe”) {  
replayBtn.\_visible = true;  
showBtn.\_visible = true;  
}  
if (qType == “col”) {  
doShow ();  
reviewBtn.\_visible = false;  
doneBtn.\_visible = false;  
doActive (false);  
}  
break;  
}  
feedback.text = outText;  
}  
function doClick (clickedBtn) {  
var btnNum:String = String (clickedBtn).substr (String (clickedBtn).length - 1, 1);  
var num:Number = Number (btnNum);  
var count:Number;  
var btnName:MovieClip;  
feedback.text = “”;  
if (numCorrect == 1) {  
for (count = 1; count \<= numDistractors; count++) {  
btnName = this[“qBtn” + count];  
btnName.btnSelected = false;  
btnName.gotoAndStop (“up”);  
}  
}  
if (numTries \< maxTries) {  
btnName = clickedBtn.\_parent[“qBtn” + num];  
if (btnName.btnSelected == true) {  
btnName.btnSelected = false;  
btnName.gotoAndStop (“up”);  
} else {  
btnName.btnSelected = true;  
btnName.gotoAndStop (“down”);  
}  
}  
}  
function doReplay () {  
var count:Number;  
var btnName:MovieClip;  
for (count = 1; count \<= numDistractors; count++) {  
btnName = this[“qBtn” + count];  
btnName.btnSelected = false;  
btnName.gotoAndStop (“up”);  
}  
numTries = 0;  
feedback.text = “”;  
replayBtn.\_visible = false;  
showBtn.\_visible = false;  
doActive (true);  
}  
function doShow () {  
var btnName:MovieClip;  
for (var count = 1; count \<= numDistractors; count++) {  
btnName = this[“qBtn” + count];  
if (btnName.correct == true) {  
btnName.gotoAndStop (“down”);  
} else {  
btnName.gotoAndStop (“up”);  
}  
}  
feedback.text = “”;  
}  
function doActive (active:Boolean) {  
var btnName:MovieClip;  
var distName:MovieClip;  
for (var count = 1; count \<= numDistractors; count++) {  
btnName = this[“qBtn” + count];  
btnName.enabled = active;  
distName = this[“distractor” + count];  
distName.enabled = active;  
}  
}  
function moveUpper(){  
var stemTextfield:MovieClip = movieId[“stem”];  
var firstDist:MovieClip = movieId[“distractor\_mc”];  
var firstBull:MovieClip = movieId[“qBtn\_mc”];  
stemTextfield.\_y = instruct.instText.\_y+instruct.instText.\_height+yoffset;  
var yNum:Number = stemTextfield.\_y+stemTextfield.\_height;  
upperLine.\_y = yNum + yoffset;  
firstDist.\_y = upperLine.\_y+yoffset;  
firstBull.\_y = firstDist.\_y-3;  
}  
function moveLower () {  
var finalDistractor:MovieClip = movieId[“distractor” + numDistractors];  
var yNum:Number = finalDistractor.\_y + finalDistractor.\_height + (yoffset + 10);  
lowerLine.\_y = yNum;  
feedback.\_y = yNum + 5;  
doneBtn.\_y = yNum + 20;  
reviewBtn.\_y = doneBtn.\_y+doneBtn.\_height;  
replayBtn.\_y = doneBtn.\_y+doneBtn.\_height;  
}  
mySound1.attachSound(“introduction”);  
mySound1 = new Sound(movieClip3);  
mySound1.attachSound(“introduction”);  
mySound1.start(0, 1);

function resetQuestion() {  
stopAllSounds();  
}  
if (tries == 2) {  
mySound1.attachSound(“incorrect”);  
mySound1 = new Sound(movieClip3);  
mySound1.attachSound(“incorrect”);  
mySound1.start(0, 1);  
}function playcorrect() {  
stopAllSounds();  
mySound1.attachSound(“correct”);  
mySound1 = new Sound(movieClip3);  
mySound1.attachSound(“correct”);  
mySound1.start(0, 1);  
}
