# Doh!

**URL:** https://forum.kirupa.com/t/doh/2902
**Category:** Uncategorized
**Created:** [March 14, 2002, 6:33am UTC](https://forum.kirupa.com/t/doh/2902 "2002-03-14T06:33:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 14, 2002, 6:33am UTC](https://forum.kirupa.com/t/doh/2902/1 "2002-03-14T06:33:27Z")

</div>

I’m trying to control (via the arrow keys) a simple box “movie” on the main stage using this code\r\ronClipEvent (keyDown) \r{\r&nbsp &nbsp &nbsp &nbsp if (Key.getCode( ) == Key.LEFT)\r&nbsp &nbsp &nbsp &nbsp {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.\_x = this.\_x - 3;\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp else if (Key.getCode( ) == Key.RIGHT\r&nbsp &nbsp &nbsp &nbsp {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.\_x = this.\_x + 3;\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp else if (Key.getCode( ) == Key.UP)\r&nbsp &nbsp &nbsp &nbsp {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.\_y = this.\_y - 3;\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp else if (Key.getCode( ) == Key.DOWN)\r&nbsp &nbsp &nbsp &nbsp {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.\_y = this.\_y + 3;\r&nbsp &nbsp &nbsp &nbsp }\r}\rI keep getting this in the Output window when I test the movie.\rScene=Scene 1, Layer=box, Frame=1: Line 8: ‘)’ expected\r &nbsp &nbsp &nbsp &nbsp {\rI’m new to AS and I still have alot to learn.\rThanks

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 14, 2002, 7:46am UTC](https://forum.kirupa.com/t/doh/2902/2 "2002-03-14T07:46:51Z")

</div>

I’m not 100% on keycodes yet, but I believe that you are approaching this incorrectly. The getKeyCode function is for getting the last key pressed. What you want is to just tell the box to do something when a key is pressed. Try this out instead.\r\ronClipEvent(enterFrame){\r if (Key.isDown(key.LEFT)){\r this.\_x-=3;\r }else if (Key.isDown(key.RIGHT)){\r this.\_x+=3;\r }else if (Key.isDown(key.UP)){\r this.\_y-=3;\r }else if (Key.isDown(key.DOWN)){\r this.\_y+=3;\r }\r}\r\rI’ve also shortened up the script for the movement itself.\rx=x+10;\ris equivilant to\rx+=10;\r\rtry out that code on the box movie clip and see if it works.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 14, 2002, 7:47am UTC](https://forum.kirupa.com/t/doh/2902/3 "2002-03-14T07:47:00Z")

</div>

Flash is trying to tell you where the syntax error in your script is:\ronClipEvent (keyDown) \r{\r if (Key.getCode( ) == Key.LEFT)\r {\r this.\_x = this.\_x - 3;\r }\r else if (Key.getCode( ) == Key.RIGHT \< here, the “)” is missing!\r {\r this.\_x = this.\_x + 3;\r }

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 14, 2002, 3:11pm UTC](https://forum.kirupa.com/t/doh/2902/4 "2002-03-14T15:11:29Z")

</div>

upu…your code worked (as it should)…Thanks\r\reyez…The missing parenthesis was the ticket…my eyesight seems to be getting worse the later at night I work on Flash.\r\rMany Thanks to you both.\r…now back to the fun!\r
