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

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

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

 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!