Audio Assets
As with visual assets, there are different methods for using audio assets in your application. We will go over the available options next.
Embedding Files
You can embed sounds in your application by adding them to your Flash library or your Flash Builder project. Embedded files should be small, like the ones used for sound effects or user interface audio feedback.
Your application will not display until all of its assets are loaded. Test it. If it sits on a black screen for too long, you may want to group the sounds in an external .swf file that you load as a separate process.
Using Flash Professional
Unless you place audio on the timeline, you need to give it a
linkage name. Go to Library→Properties→Linkage and click on Export for
ActionScript. Change the name so that it doesn’t include an
extension, and add a capital letter to conform to class naming
conventions. For instance, “mySound.mp3” should be “MySound”. Note
that the Base
class becomes
flash.media.Sound
:
var mySound:MySound = new MySound(); mySound.play();
Using Flash Builder
Place your audio file in your project folder. Embed it and assign it to a class so that you can create an instance of it:
import flash.media.Sound; [Embed(source="mySound.mp3")] public var Simple:Class; var mySound:Sound = new Simple as Sound; mySound.play();
Using External Files
Using external files is best for long sounds or if you want the flexibility to replace the files without recompiling your application. Please review Chapter 4 on how to ...
Get Developing Android Applications with Adobe AIR now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.