# \[Flash8\] Problem getting sound to play when Keyboard button is hit

**URL:** <https://forum.kirupa.com/t/flash8-problem-getting-sound-to-play-when-keyboard-button-is-hit/301496>\
**Category:** flash\
**Created:** [December 10, 2009, 2:38am UTC](https://forum.kirupa.com/t/flash8-problem-getting-sound-to-play-when-keyboard-button-is-hit/301496 "2009-12-10T02:38:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dirty\_d](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@Dirty\_d](https://forum.kirupa.com/u/Dirty_d)\
**Post date:** [December 10, 2009, 2:38am UTC](https://forum.kirupa.com/t/flash8-problem-getting-sound-to-play-when-keyboard-button-is-hit/301496/1 "2009-12-10T02:38:36Z")

</div>

I think worded the question wrong or posted in the wrong catagory

I keep geting error messages with this code in AS2.0

```auto
 if (key.isDown(key.getCode(81))) {
 _root.samplesound=new Sound();
 _root.samplesound.attachSound("sample1")
 _root.samplesound.start(.1, 0);
}
if (!key.isdown(81)) {
 sound.stop();
} 

```

This is the message fore both pieces

> Statement must appear within on/onClipEvent handler

Im trying to get the letter “q” to play a linked mp3 in my library

When I apply the code to a seperate layer No error messages shows, but no sound plays. When I apply the code to a movie clip/button object, that message shows up!

I’m Completly stumped. If anybody can help I would greatly apreciate it!
