Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.display.*;
- import flash.events.*;
- import flash.text.*;
- import flash.utils.getTimer;
- import flash.utils.Timer;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.ui.Mouse;
- /*
- the aim of this program is to have a timer that infinitely repeats, and at every 50
- seconds, it plays a sound. Unfortunately, I cannot get the countdown to work nor
- the sound to play after the 50 seconds. The Output will trace "Timer Started", but will trace this error every 50 seconds:
- ArgumentError: Error #2068: Invalid sound.
- at flash.media::Sound/play()
- at Untitled_fla::MainTimeline/playSound()
- at flash.utils::Timer/_timerDispatch()
- at flash.utils::Timer/tick()
- Thanks for your help
- */
- //variables
- var timeLeft:uint = 50000;
- var timer:Timer = new Timer(timeLeft,0); //fires infinite times
- var beepSound:Sound = new Sound();
- //event listeners
- startButton.addEventListener(MouseEvent.CLICK, startTimer);
- function startTimer (e:MouseEvent)//start timer, start countdown, disable button
- {
- timer.start();
- trace("Timer Started");
- startButton.visible = false;
- timer.addEventListener(TimerEvent.TIMER, playSound);
- }
- function playSound (soundObject: Object)
- {
- beepSound.play();
- trace("Sound Played");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement