2013-04-29 1 views
0

좋아요, 좋아요, 그래서 제가 만들고있는 웹 사이트의 간단한 액션 스크립트 3 사운드 플레이어를 작업 중입니다 ... 그리고 그렇게하면서 SOUND_COMPLETE 이벤트가 발생했습니다. 웬일인지 발사하지 않는다. 따라서 누군가 내 코드에서 문제를 발견 한 것으로 보이는 경우 응답하십시오!Actionscript 3 : Event.SOUND_COMPLETE가 실행되지 않습니다.

package { 
    import flash.events.*; 
    import flash.media.*; 
    import flash.external.*; 
    import flash.net.*; 
    import flash.utils.*; 

    public class player{ 

     private var soundChannel:SoundChannel; 
     private var sound:Sound; 
     private var lastPosition:Number = 0; 

     public function player():void{ 
      ExternalInterface.addCallback("load", this.load); 
      ExternalInterface.addCallback("play", this.play); 
      ExternalInterface.addCallback("stop", this.stop); 
      ExternalInterface.addCallback("reset", this.reset); 
     } 
     /* 
     javascript from inside actionscript: 

      ExternalInterface.call("console.log","ipsum"); 
     */ 
     private function load(url:String):void{ 
      var audio:URLRequest = new URLRequest(url); 
      try { 
       this.soundChannel.stop(); 
      } catch(e:Error) { 
      }; 
      this.sound = new Sound(); 
      this.sound.load(audio); 
      this.lastPosition = 0; 
     } 
     private function play():void{ 
      this.soundChannel = this.sound.play(this.lastPosition); 
      this.soundChannel.addEventListener(Event.SOUND_COMPLETE,finished); 
      ExternalInterface.call("console.log","started playing"); 
     } 
     private function finished():void{ 
      this.lastPosition=0; 
      this.soundChannel=this.sound.play() 
      ExternalInterface.call("console.log","finished playing"); 
     } 
     private function reset():void{ 
      this.lastPosition = 0; 
      this.soundChannel.stop(); 
     } 
     private function stop():void{ 
      try { 
       this.lastPosition = this.soundChannel.position; 
       this.soundChannel.stop(); 
      } catch(e:Error) { 
      }; 
     } 

    } 
}//package 
+0

http://www.untoldentertainment.com/blog/2009/10/14/as3 -pitfalls-sound_complete-event-is-not-firing/ – adaam

+0

이 경우에는 Play 함수를 사용할 때마다 EventListener가 다시 추가되므로이 경우에는 해당되지 않습니다. 답변 해 주셔서 감사합니다. –

+2

로드에서 로컬 정지 함수를 호출해야한다고 생각합니다. 완성 된() 함수에서 런타임 오류가 발생한다고 생각합니다. 전달 된 이벤트를 수락 할 수 없기 때문입니다. 런타임 오류로 인해 코드가 실행되지 않습니다. 디버깅을 사용 중지했거나 디버그 플레이어에서 실행하지 않았기 때문에 사용자가 볼 수 없다고 가정 할 수 있습니다. –

답변

0

나는 문제가 이벤트를 수락하지 않습니다 finished(), 그것은되어야한다고 믿습니다 :

private function finished(e:Event):void{ 
     this.lastPosition=0; 
     this.soundChannel=this.sound.play() 
     ExternalInterface.call("console.log","finished playing"); 
    } 
+0

지금 당장 작동하는 것 같습니다! 정말 고맙습니다. –

관련 문제