2010-04-02 4 views
0

Je pensais que je pourrais changer la valeur booléenne vrai/faux, mais ça ne fonctionne pas. Comment puis-je obtenir ce silence, jusqu'à ce que le bouton soit pressé?film silencieux jusqu'à ce que le bouton presse, flash as3

import flash.media.Sound; 
import flash.media.SoundChannel; 

var soundOn:Boolean = true; //music is ON when we start 
var myToons:TitleMusic = new TitleMusic(); 
var myChannel:SoundChannel = myToons.play(0,1000); // endless loop, in effect 
var myTransform:SoundTransform; 

mySoundButton.addEventListener(MouseEvent.CLICK,toggleSound); 
mySoundButton.buttonMode = true; 
mySoundButton.mouseChildren = false; 


function toggleSound(e:MouseEvent) 
{ 
    if(soundOn) 
    { 
     // turn sound off 
     myTransform = new SoundTransform(); 
     myTransform.volume = 0; // silent 
     myChannel.soundTransform = myTransform; 
     soundOn = false; 
     mySoundButton.myButtonText.text = "click to turn sound ON"; 
    } 
    else // sound is off 
    { 
     // turn sound on 
     myTransform = new SoundTransform(); 
     myTransform.volume = 1; // full volume 
     myChannel.soundTransform = myTransform; 
     soundOn = true; 
     mySoundButton.myButtonText.text = "click to turn sound OFF"; 
    } 

} 

Répondre

1

Vous n'avez pas besoin d'instructions booléennes. Voici ce que j'ai fait.

La variable 'mySound' instancie les sons. Je passe le contrôle du son à 'myChannel'. Les boutons du panneau des composants ont leur nom. Assurez-vous de configurer correctement vos propriétés mp3, Name 'Sound, Class' Sound '. Tout devrait fonctionner!

lecture et d'arrêt intégré mp3

   /*  
       place mp3 in library. 
       Give it a Name and Class of 'Sound' 
       */ 
     var mySound:Sound = new Sound(); 
       //control the channel that your sound is on 
     var myChannel:SoundChannel = new SoundChannel(); 
playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler); 
       /* 
       Grab a Play and Stop button from the components menu. 
       Go to Properties Panel and give each an instance name. 
       Play is 'playButton', Stop is 'stopButton' 
       */ 
     function myPlayButtonHandler (e:MouseEvent):void { 
       //mySound.play();//use channel instead 
      myChannel = mySound.play(); 
      } 
       //Stopping the sound channel 
stopButton.addEventListener(MouseEvent.CLICK, onClickStop); 
     function onClickStop(e:MouseEvent):void{ 
      myChannel.stop(); 
      } 

Load option mp3 externe

  //URL load and auto play of external file "myMp3.mp3" 
      var mySound:Sound = new Sound(); 
      snd.load(new URLRequest("myMp3.mp3")); 
      snd.play(); 
+0

Merci, qui a sauvé mes fesses. Je n'ai pas trouvé de tutoriel comme celui-ci. Merci encore:) – pixelGreaser