如何在用户单击正确答案时播放声音

时间:2016-05-01 17:12:48

标签: android actionscript-3 flash audio animate-cc

我使用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");

            }

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

如果您将 if ( $request->isMethod( 'POST' )) { $date= ($request->getContent('date')); $date= new Response($date, 200); if ((date('d-m-Y') == $date)) { return $date; } else { some stuff }声明为mySound声音的变量名称,则在按代码访问时使用完全相同的名称。

WrongAnswer();

如果还有问题,请告诉我。我要提供的替代方法是通过代码嵌入声音,但这可能不是必要的......