1

AS3 を使用してフラッシュでクイズを作成しています。ユーザーが正解または不正解をクリックしたときにサウンドを含めようとして問題が発生しました。

サウンドを正しく再生するにはどうすればよいですか?

これは以下のコードです

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

mySoundサウンドの変数名として宣言した場合はWrongAnswer();、コードでアクセスするときにまったく同じ名前を使用します。

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 に答える