Skip to main content
Inspiring
February 26, 2025
Answered

AS3, Sound pause and rePlay

  • February 26, 2025
  • 1 reply
  • 384 views

There is an issue where the replay button does not work after a long pause (3 minutes or more) while playing music.
I don't know why.

 

var pausePosition: Number;
// stageOnOff => Video clip

stageOnOff.addEventListener(MouseEvent.CLICK, playpauseSelect);
var onOff: Boolean = false;

function playpauseSelect(e: MouseEvent): void {

	onOff = !onOff;

	if ( onOff) {
		pausePosition = channel.position;
		channel.stop();
	} else {
		channel = sound.play(pausePosition);
		channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
	}

}

 

    Correct answer Rucca Cina

    [AS3] How to pause Movie Clip, Frame, and Sound at the same time?

     

    글로벌 게시판에서 해당 내용을 참고해 봤습니다. 

    현재 재생 중인 모든 사운드와 정지 시의 위치를 배열로 유지할 수 있습니다.

    그런 다음 올바른 위치에서 다시 시작할 수 있습니다.

    만약 네 개의 사운드, a.mp3, b.mp3, c.mp3, d.mp3가 있고, 정지 버튼과 시작 버튼이 있다면, 이 코드는 모든 사운드를 재생하고, 이를 멈춘 후, 중단된 위치에서 계속 재생할 수 있게 해줍니다.

     

     

    import flash.media.Sound;

    import flash.media.SoundChannel;

    import flash.net.URLRequest;

    import flash.events.MouseEvent;

     

    var files:Array = ["a.mp3","b.mp3","c.mp3","d.mp3"];

    var sounds:Array = [];

    var soundchannels:Array = [];

    var soundpositions:Array = [];

    startsounds();

    stopbtn.addEventListener(MouseEvent.CLICK,stopsounds);

    startbtn.addEventListener(MouseEvent.CLICK,playsounds);

    stop();

    function startsounds(){

      var i:int;

      var snd:Sound;

      var chn:SoundChannel;

      soundchannels = [];

      for(i = 0;i< files.length;i++){

      snd = new Sound(new URLRequest(files));

      chn = snd.play();

      sounds.push(snd);

      soundchannels.push(chn);

      }

    }

    function stopsounds(e:MouseEvent){

      var i:int;

      var chn:SoundChannel;

      soundpositions = [];

      for(i = 0;i< sounds.length;i++){

      chn = soundchannels;

      soundpositions.push(chn.position);

      chn.stop();

      }

    }

    function playsounds(e:MouseEvent){

      var i:int;

      var chn:SoundChannel;

      soundchannels = [];

      for(i = 0;i< sounds.length;i++){

      chn = sounds.play(soundpositions);

      soundchannels.push(chn);

      }

    }

     

    해당 수식을 참고할 수 있을것 같습니다. 

    1 reply

    Rucca CinaCorrect answer
    Legend
    February 28, 2025

    [AS3] How to pause Movie Clip, Frame, and Sound at the same time?

     

    글로벌 게시판에서 해당 내용을 참고해 봤습니다. 

    현재 재생 중인 모든 사운드와 정지 시의 위치를 배열로 유지할 수 있습니다.

    그런 다음 올바른 위치에서 다시 시작할 수 있습니다.

    만약 네 개의 사운드, a.mp3, b.mp3, c.mp3, d.mp3가 있고, 정지 버튼과 시작 버튼이 있다면, 이 코드는 모든 사운드를 재생하고, 이를 멈춘 후, 중단된 위치에서 계속 재생할 수 있게 해줍니다.

     

     

    import flash.media.Sound;

    import flash.media.SoundChannel;

    import flash.net.URLRequest;

    import flash.events.MouseEvent;

     

    var files:Array = ["a.mp3","b.mp3","c.mp3","d.mp3"];

    var sounds:Array = [];

    var soundchannels:Array = [];

    var soundpositions:Array = [];

    startsounds();

    stopbtn.addEventListener(MouseEvent.CLICK,stopsounds);

    startbtn.addEventListener(MouseEvent.CLICK,playsounds);

    stop();

    function startsounds(){

      var i:int;

      var snd:Sound;

      var chn:SoundChannel;

      soundchannels = [];

      for(i = 0;i< files.length;i++){

      snd = new Sound(new URLRequest(files));

      chn = snd.play();

      sounds.push(snd);

      soundchannels.push(chn);

      }

    }

    function stopsounds(e:MouseEvent){

      var i:int;

      var chn:SoundChannel;

      soundpositions = [];

      for(i = 0;i< sounds.length;i++){

      chn = soundchannels;

      soundpositions.push(chn.position);

      chn.stop();

      }

    }

    function playsounds(e:MouseEvent){

      var i:int;

      var chn:SoundChannel;

      soundchannels = [];

      for(i = 0;i< sounds.length;i++){

      chn = sounds.play(soundpositions);

      soundchannels.push(chn);

      }

    }

     

    해당 수식을 참고할 수 있을것 같습니다. 

    Inspiring
    February 28, 2025

    Thank you for your kind comments.