How to embed mp3 in FlashDevelop

Let's say you have a game project in FlashDevelop, and you want some nice music to be playing in this game. There are some articles and forum posts about how to embed mp3 in FlashDevelop, but all of them are doing it too complicated. This is the easiest way I found to do it:

  1. Put the mp3 file in your project's directory somewhere, so you can see it in FlashDevelop,
  2. Insert the mp3 file in the document,
  3. Create the Class for sound, and one variable of type Sound:
     		 
    [Embed(source='../res/out.mp3')] 		 
    private var MySound : Class; 		 
    private var sound : Sound; // not MySound! 		 
    public function Main() : void  { 	 
    
  4. Play the sound:
     		 
    [Embed(source='../res/out.mp3')] 		 
    private var MySound : Class; 		 
    private var sound : Sound; 		 
    public function Main() : void  { 			     
        sound = (new MySound) as Sound; 			     
        sound.play(); 			     
        super(); 		 
    } 	 

And that's all. See, easy.


Discussion:
Add post
jim said on Saturday, 30-Jan-10 20:10:47 CET
Thanks Dude! It WAS easy. (Because it worked!)
Tiziano said on Friday, 30-Apr-10 20:19:55 CEST
Good! But don't forget to import Sound class: import flash.media.Sound; ;)
said on Sunday, 23-Oct-11 23:19:08 CEST
Anonymous said on Tuesday, 01-Nov-11 17:44:14 CET
It does not work. There's no Insert Into Document when I right click my MP3s.
said on Monday, 19-Dec-11 20:21:33 CET