Sunday, January 13, 2013

How to embed sounds and music in FlashDevelop AS3 project

Its really easy. Lets have soundfile sound.mp3 in folder music.

        [Embed(source='../music/sound.mp3')]        
        private var musicClass : Class;        
        private var mymusic : Sound;

And then this:

         myMusic = (new musicClass) as Sound;                 
         myMusic.play();

Here is the full sourcecode:

package 
{
   
    public class MusicTest
    {
       
        [Embed(source='../music/sound.mp3')]         
        private var musicClass : Class;         
        private var myMusic : Sound;
       
        public function MusicTest()
        {
            myMusic = (new musicClass) as Sound;         
        }
       
        public function playMusic():void {
            myMusic.play();
        }
       
    }

}

No comments :

Post a Comment