AS3 Sound Listeners


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var soundPlaying:Boolean = false;
  2. var _playPosition:int;
  3.  
  4.  
  5. //This is your code here hannah
  6.  
  7. var snd:Sound = new Sound();
  8. snd.load(new URLRequest("http://www.lazytoolbox.co.uk/05BLACKLOCUST.mp3"));
  9. var channel:SoundChannel = new
  10. SoundChannel();
  11. channel = snd.play(0, int.MAX_VALUE);
  12. soundPlaying = true;
  13.  
  14. ////////////////////////
  15.  
  16. //////////////////////////
  17. // Stuff I Added in //
  18. //////////////////////////
  19.  
  20. pausebuttonname.addEventListener(MouseEvent.CLICK, onPause);
  21.  
  22. //Code for Pause
  23.  
  24. public function onPause(Event:MouseEvent):void {
  25. if(soundPlaying == true) {
  26. _playPosition = channel.position
  27. channel.stop();
  28. soundPlaying = false;
  29. }
  30. else
  31. {
  32. channel = sound.play(_playPosition);
  33. soundPlaying = true;
  34. }
  35.  
  36.  
  37.  
  38.  
  39. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.