Thursday, May 22, 2008

Sound Assets

There are two ways to play sounds in ActionScript: via assets and via streams. This entry will demonstrate how to create and play sound assets.
  1. Right click and save this MP3 as small_sample.mp3 in the src directory. On my machine, the full path is:
    /home/kca/workspace/hello_world/src/
  2. Copy and paste this XML into asset.xml in the src directory
  3. At the command prompt, run this command in the src directory:
    swfmill simple asset.xml asset.swf
  4. This will rebuild the asset library. A new SWF file should now exist in the src directory called asset.swf.
  5. Double click source file Application.as to edit
  6. At the bottom of function init, add this code:
    var snd:Sound = new Sound() ;
    snd.attachSound("asset_small_sample") ;
    snd.start() ;
  7. Save the file, and the SWF file is automatically rebuilt by Eclipse. Click to hear the MP3 play after the preloader finishes.


No comments: