Monday, 6 April 2015
How to load audio sound mp3 files with Starling Framework
Similarly, an Android game without any background music or sound effect wont keep the players long. Hence, it is important to know how to load audio/sound files into your game, playing them at a correct timing. Here, the codes for doing it with Starling Framework will be displayed.
1. Import Flashs Sound library
It is alright to just use the Sound library from the Flash. In fact, there isnt any specific library for the sound in Starling Framework.import flash.media.Sound;
2. Embed the audio/sound file
Like embedding the image files, embedding an audio/sound is similarly straightforward.[Embed(source="../media/sounds/move.mp3")]
public const MOVE_SOUND:Class;
3. Define the sound variable
Here, note that it is necessary to use "as Sound" when defining the variable.public var sndMove:Sound = new MOVE_SOUND() as Sound;
4. Play the audio/sound file
With the play function, you can directly play the audio file, with customizable parameters. (specify start time, loop times, sound transform)sndMove.play()