# Playing a random embedded sound

**URL:** <https://forum.kirupa.com/t/playing-a-random-embedded-sound/227244>\
**Category:** flash\
**Created:** [May 28, 2007, 8:46pm UTC](https://forum.kirupa.com/t/playing-a-random-embedded-sound/227244 "2007-05-28T20:46:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndc](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@ndc](https://forum.kirupa.com/u/ndc)\
**Post date:** [May 28, 2007, 8:46pm UTC](https://forum.kirupa.com/t/playing-a-random-embedded-sound/227244/1 "2007-05-28T20:46:02Z")

</div>

I’d like to play a random embedded MP3, but my efforts so far have been unsuccessful:

```auto

//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?
