Flex Demo 7 - Playing Embedded Sound

View Flex Demo 7

This sample demonstrates the ability to play sound samples that are embedded within the swf file itself. Embedding the sound file within the swf should usually be used when the sounds are relatively small and short, or they need to be loaded quickly.

This program contains only a few sections of important code. The basic components are laid out in an HGroup container:
    <s:HGroup x="10" y="10" width="449" height="45"> 
        <s:Button label="Play Sample 1" click="cello1.play()" /> 
        <s:Button label="Play Sample 2" click="cello2.play()" /> 
        <s:Button label="Play Sample 3" click="cello3.play()" /> 
    </s:HGroup> 
The ActionScript section contains code that embeds the three mp3 files, and creates a SoundAsset object for each one.
        import mx.controls.Alert;
        import mx.core.SoundAsset;
        
        [('assets/cello1.mp3')] 
        private var cello1class:Class;
        private var cello1:SoundAsset = new cello1class() as SoundAsset;
        
        [('assets/cello2.mp3')] 
        private var cello2class:Class;
        private var cello2:SoundAsset = new cello2class() as SoundAsset;
        
        [('assets/cello3.mp3')] 
        private var cello3class:Class;
        private var cello3:SoundAsset = new cello3class() as SoundAsset;