[ AS3 ] un soundchannel qui ne veut pas s'arreter

Résolu
ptitvincent Messages postés 34 Date d'inscription mardi 30 juin 2009 Statut Membre Dernière intervention 1 novembre 2010 - 27 oct. 2010 à 14:58
ptitvincent Messages postés 34 Date d'inscription mardi 30 juin 2009 Statut Membre Dernière intervention 1 novembre 2010 - 27 oct. 2010 à 15:46
Bonjour à tous,

Dans le code suivant je fais une boucle (classique) d'un son.
Je suis dans la situation d'un menu de démarrage d'un jeu.

Quand J'appuie sur mon bouton start, je lui demande de stopper le canal.
... Et bien il me dit que canal n'existe pas (" acces à la propriété non défini canal.stop(); ")

stop();
var soon:Boolean=false;
import flash.media.SoundChannel;
import flash.events.Event;
import MusicLoop1;

var snd1:Sound = new MusicLoop1();

startSound1(snd1); 

function startSound1(sound1:Sound):void{
var canal:SoundChannel = sound1.play();
canal.addEventListener(Event.SOUND_COMPLETE,replay1);
soon=true;
}

function replay1(e:Event):void{
startSound1(snd1);
}



btn_start.addEventListener(MouseEvent.MOUSE_OVER, gamestartover);
btn_start.addEventListener(MouseEvent.MOUSE_OUT, gamestartout);
btn_start.addEventListener(MouseEvent.CLICK, gamestartclick);

function gamestartover(event:MouseEvent):void
{
    btn_start.width+=60;
    btn_start.height+=30;
}
function gamestartout(event:MouseEvent):void
{
    btn_start.width-=60;
    btn_start.height-=30;
}

function gamestartclick(event:MouseEvent):void
{
    canal.stop();
    btn_start.removeEventListener(MouseEvent.MOUSE_OVER, gamestartover);
    btn_start.removeEventListener(MouseEvent.MOUSE_OUT, gamestartout);
    btn_start.removeEventListener(MouseEvent.CLICK, gamestartclick);
    gotoAndStop(2);

}


Merci d'avance pour votre aide.

Vince.

1 réponse

ptitvincent Messages postés 34 Date d'inscription mardi 30 juin 2009 Statut Membre Dernière intervention 1 novembre 2010
27 oct. 2010 à 15:46
Apres un ptit café j'ai pu trouver la solution, désolé d'avoir posté pour rien :)

Il suffisait de créer le soundchannel en dehors de la fonction.

Pour ceux qui éventuellement auraient fait la meme erreur :

stop();
import flash.media.SoundChannel;
import flash.events.Event;
import MusicLoop1;
var canal:SoundChannel=new SoundChannel();

var snd1:Sound = new MusicLoop1();

startSound1(snd1); 

function startSound1(sound1:Sound):void{
canal = sound1.play();
canal.addEventListener(Event.SOUND_COMPLETE,replay1);
}


Merci à bientot.
3
Rejoignez-nous