Songs read by the Google Dictionnary

Flash player 9 required. Missing words from the dictionnary are skipped.

Source :

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	[SWF(width='800', height='300', backgroundColor='#000000', frameRate='5')]

	public class GoogleDictionnary extends Sprite
	{
		private var _sound:Sound;
		private var _channel:SoundChannel;
		private var _source:String;
		private var _word:String;
		private var _numWords:int;
		private var _currentWord:int;
		private var _words:Array;
		private var _field:TextField;

		public function GoogleDictionnary()
		{
			init();
		}

		private function init():void
		{
			_field = new TextField();
			_field.y = 100;
			_field.width = stage.stageWidth;
			_field.height = 200;
			_field.mouseEnabled = false;
			_field.selectable = false;
			_field.defaultTextFormat = new TextFormat( 'Arial', 80, 0xFFFFFF, true, false, false, null, null, TextFormatAlign.CENTER );
			addChild( _field );

			// let it be
			//_source = "When I find myself in times of trouble mother marry come to me speaking word of wisdom let it be And in my hour of darkness she is standing right in front of me speaking word of wisdom let it be Let it be let it be let it be let it be Whisper word of wisdom let it be And when the broken hearted people living in the world agree there will be an answer let it be For though they may be parted there is still a chance that they will see there will be an answer let it be Let it be let it be And when the night is cloudy there is still a light that shines on me shine until tomorrow let it be I wake up to the sound of music mother marry come to me speaking word of wisdom let it be Let it be let it be";

			// light my fire
			//_source = "You know that it would be untrue  You know that I would be a liar  If I was to say to you  Girl, we couldn't get much higher  Come on baby, light my fire  Come on baby, light my fire  Try to set the night on fire   The time to hesitate is through  No time to wallow in the mire  Try now we can only lose  And our love become a funeral pyre  Come on baby, light my fire  Come on baby, light my fire  Try to set the night on fire, yeah   The time to hesitate is through  No time to wallow in the mire  Try now we can only lose  And our love become a funeral pyre  Come on baby, light my fire  Come on baby, light my fire  Try to set the night on fire, yeah   You know that it would be untrue  You know that I would be a liar  If I was to say to you  Girl, we couldn't get much higher  Come on baby, light my fire  Come on baby, light my fire  Try to set the night on fire  Try to set the night on fire  Try to set the night on fire  Try to set the night on fire ";

			// no woman no cry
			// _source = "No, woman, no cry; No, woman, no cry; No, woman, no cry; No, woman, no cry.  Said I remember when we used to sit In a government yard in Trenchtown, Oba - observing the hypocrites  Mingle with the good people we meet Good friends we have, oh good friends we've lost Along the way, yeah! In this great future, you can't forget your past So dry your tears, I say,yeah!  No, woman, no cry; No, woman, no cry. Little darling, don't shed no tears No woman, no cry.   Said I remember when we used to sit In the government yard in Trenchtown,  And then Georgie would make the fire lights, Logwood burnin' through the nights,  Then we would cook cornmeal porridge,  Of which I'll share with you, ouh! My feet is my only carriage And so I've got to push on through. But while I'm gone, Everything's gonna be all right!  Everything's gonna be all right! Everything's gonna be all right,  Everything's gonna be all right! Everything's gonna be all right! Everything's gonna be all right! Everything's gonna be all right,  Everything's gonna be all right!  No, woman, no cry No, woman, no cry. Little darling,don't shed no tears No, woman, no cry, eh.";

			// enter sandman
			_source = "Say your prayer little one don't forget, my son To include everyone  Tuck you in, warm within Keep you free from sin Till the sandman he come  Sleep with one eye open Gripping your pillow tight  Exit light Enter night Take my hand Off to never never land  Something is wrong, shut the light Heavy thought tonight And they arent of snow white  dream of war, dream of liar dream of dragon fire And of thing that will bite  Sleep with one eye open Gripping your pillow tight  Exit light Enter night Take my hand Off to never never land  Now I lay me down to sleep Pray the lord my soul to keep If I die before I wake Pray the lord my soul to take  Hush little baby, don't say a word And never mind that noise you heard Its just the beast under your bed, In your closet, in your head  Exit light Enter night Grain of sand  Exit light Enter night Take my hand Were off to never never land";

			_source = _source.replace( /\s+/g, ' ' ); // remove multiple spaces
			_source = _source.replace( /[\*:,;.\/\n\t]/g, '' ); // remove punctuation

			_words = _source.split( ' ' );
			_numWords = _words.length;
			_currentWord = 0;
			nextWord();
		}

		private function nextWord():void
		{
			if ( _currentWord < _numWords ) 
			{
				loadWord( _words[ _currentWord ] );
				++_currentWord;
			}
			else
			{
				_field.text = '';
			}
		}

		private function loadWord( word:String ):void
		{
			_field.text = word;
			_word = word.toLowerCase();
			_sound = new Sound();
			_sound.addEventListener( IOErrorEvent.IO_ERROR, onLoadError );
			_sound.addEventListener( Event.OPEN, onLoadStart );
			_sound.load( new URLRequest( 'http://www.google.be/dictionary/sounds/' + _word + '.mp3' ) );
		}

		private function onLoadStart( event:Event ):void
		{
			//trace("playing : " + _word );
			_channel = _sound.play();
			_channel.addEventListener( Event.SOUND_COMPLETE, onSoundComplete );
		}

		private function onLoadError( event:IOErrorEvent = null ):void
		{
			//trace("error, not playing " + _word );
			_sound.removeEventListener( IOErrorEvent.IO_ERROR, onLoadError );
			_sound.removeEventListener( Event.OPEN, onLoadStart );
			_sound = null;
			nextWord();
		}

		private function onSoundComplete( event:Event = null ):void
		{
			_channel.removeEventListener( Event.SOUND_COMPLETE, onSoundComplete );
			_channel = null;
			nextWord();
		}
	}
}

Contact : emeric (at) minimal (dot) be