2016-05-01 5 views
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"); 

      } 

答えて

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

このコードでは、音楽を再生することができますありません。 コードをOnclick()メソッドの内部に配置します。

+0

私はこれを試してみました。私はこれを正しくしましたか? –

+0

あなたの活動名は何ですか?私はちょうどYourActivityを無作為に保った!あなたのアクティビティ名を書く必要があります、クラス名 –

+0

@TripatheeGaurav、これはAndroid SDKコードですか? AskerはAS3(Flash)コードを使用してAndroidアプリを作成しています。 –

0

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

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"); 
    } 

} 

まだ問題がある場合は、教えてください。私が与えるつもりだったのは、コードでサウンドを埋め込むだけでしたが、ここでは必要ないかもしれません...

関連する問題