I’d like to play a random embedded MP3, but my efforts so far have been unsuccessful:
//embed sounds
[Embed(source="assets/sound/1.mp3")]
private static var sfxLibrary1:Class;
[Embed(source="assets/sound/2.mp3")]
private static var sfxLibrary2:Class;
[Embed(source="assets/sound/3.mp3")]
private static var sfxLibrary3:Class;
// other sounds embedded here...
// ---- code removed for brevity ------ //
//create and play a random sound effect
var sfxNo:Number = Math.floor( Math.random( ) * 3 ) + 1;
var ClassReference:Class = getDefinitionByName("sfxLibrary"+String(sfxNo)) as Class;
var sfx:Sound = Sound(new ClassReference());
sfx.play();
When debugging, the thread is suspended with “ReferenceError:Error #1065: Variable sfxLibrary3 is not defined”
Can anyone see where I’m going wrong, or think of a better way of doing it?