# atatchSound onPress instead of onKeyDown?

**URL:** <https://forum.kirupa.com/t/atatchsound-onpress-instead-of-onkeydown/194792>\
**Category:** flash\
**Created:** [July 26, 2006, 11:52am UTC](https://forum.kirupa.com/t/atatchsound-onpress-instead-of-onkeydown/194792 "2006-07-26T11:52:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickedBoy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wickedboy/32/1100_2.png) [@wickedBoy](https://forum.kirupa.com/u/wickedBoy)\
**Post date:** [July 26, 2006, 11:52am UTC](https://forum.kirupa.com/t/atatchsound-onpress-instead-of-onkeydown/194792/1 "2006-07-26T11:52:09Z")

</div>

How could I alter this code so that it works onPress?

```auto
var ranSound = new Sound(this);
ranSound.onPress = function() {
        if (Key.isDown(Key.SPACE)) {
                this.stop();
                this.attachSound("s"+Math.round(Math.random()*11));
                this.start();
        }
};
Key.addListener(ranSound);

```
