SHARE
TWEET

ActionScript 3 Invalid Sound Problem

Dettefin Oct 3rd, 2013 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.display.*;
  2. import flash.events.*;
  3. import flash.text.*;
  4. import flash.utils.getTimer;
  5. import flash.utils.Timer;
  6. import flash.media.Sound;
  7. import flash.media.SoundChannel;
  8. import flash.ui.Mouse;
  9.  
  10.  
  11. /*
  12. the aim of this program is to have a timer that infinitely repeats, and at every 50
  13. seconds, it plays a sound. Unfortunately, I cannot get the countdown to work nor
  14. the sound to play after the 50 seconds. The Output will trace "Timer Started", but will trace this error every 50 seconds:
  15.  
  16. ArgumentError: Error #2068: Invalid sound.
  17.         at flash.media::Sound/play()
  18.         at Untitled_fla::MainTimeline/playSound()
  19.         at flash.utils::Timer/_timerDispatch()
  20.         at flash.utils::Timer/tick()
  21.  
  22. Thanks for your help
  23. */
  24.  
  25. //variables
  26. var timeLeft:uint = 50000;
  27. var timer:Timer = new Timer(timeLeft,0); //fires infinite times
  28. var beepSound:Sound = new Sound();
  29. //event listeners
  30. startButton.addEventListener(MouseEvent.CLICK, startTimer);
  31.  
  32.  
  33. function startTimer (e:MouseEvent)//start timer, start countdown, disable button
  34. {
  35.         timer.start();
  36.         trace("Timer Started");
  37.         startButton.visible = false;
  38.         timer.addEventListener(TimerEvent.TIMER, playSound);
  39.        
  40. }
  41.  
  42. function playSound (soundObject: Object)
  43. {
  44.         beepSound.play();
  45.         trace("Sound Played");
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top