1

我正在使用 AS3 在 Flash 中创建一个测验。当用户单击正确或错误的答案时,我无法尝试包含声音。

如何正确播放声音?

这是下面的代码

import flash.media.Sound;

//button 1, see if the first text field equals the answer, if it does it plays the correct scene, if it doesnt it plays incorrect scene
myTextField11.addEventListener(MouseEvent.MOUSE_UP,state11);
function state11(evt:MouseEvent)
{
    if (myTextField11.text == answer1){
            trace("Correct answer!!");
            gotoAndPlay(2,"quiz1");
            count = count + 10;
            scoreBox.text = (count).toString();
            setTimeout(gotoAndPlay, 1250, 1, "quiz2");


        } else {
                trace(myTextField11);
                gotoAndPlay(3,"quiz1"); 
                var mySound:Sound = new WrongAnswer();
                WrongAnswer.play();
                setTimeout(gotoAndPlay, 1250, 1,"quiz2");

                }
}

我现在已经做到了,但没有运气:

import flash.media.Sound;

//button 1, see if the first text field equals the answer, if it does it plays the correct scene, if it doesnt it plays incorrect scene
myTextField11.addEventListener(MouseEvent.MOUSE_UP,state11);
function state11(evt:MouseEvent)
{
    if (myTextField11.text == answer1){
            trace("Correct answer!!");
            gotoAndPlay(2,"quiz1");
            count = count + 10;
            scoreBox.text = (count).toString();
            setTimeout(gotoAndPlay, 1250, 1, "quiz2");


        } else {
                trace(myTextField11);
                gotoAndPlay(3,"quiz1");

                MediaPlayer player = MediaPlayer player=MediaPlayer.create(YourActivity.this,R.raw.WrongAnswer);
player.start();


            setTimeout(gotoAndPlay, 1250, 1,"quiz2");

            }
4

2 回答 2

1
MediaPlayer player=MediaPlayer.create(YourActivity.this,R.raw.nameofile);
player.start();

此代码有助于播放音乐。将代码放在 Onclick() 方法中。

于 2016-05-01T17:22:39.610 回答
0

如果您声明mySoundWrongAnswer();声音的变量名,则在通过代码访问时使用完全相同的名称。

import flash.media.Sound;

//button 1, see if the first text field equals the answer, if it does it plays the correct scene, if it doesnt it plays incorrect scene
myTextField11.addEventListener(MouseEvent.MOUSE_UP,state11);
function state11(evt:MouseEvent)
{
    if (myTextField11.text == answer1)
    {
        trace("Correct answer!!");
        gotoAndPlay(2,"quiz1");
        count = count + 10;
        scoreBox.text = (count).toString();
        setTimeout(gotoAndPlay, 1250, 1, "quiz2");
    } 
    else 
    {
        trace(myTextField11);
        gotoAndPlay(3,"quiz1"); 
        var mySound:Sound = new WrongAnswer();
        //WrongAnswer.play();
        mySound.play();
        setTimeout(gotoAndPlay, 1250, 1,"quiz2");
    }

}

如果还有问题,请告诉我。我要给出的替代方案是通过代码嵌入声音,但这在这里可能没有必要......

于 2016-05-01T19:14:33.810 回答