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        if (Key.getCode( ) == Key.LEFT)\r        {\r                this._x = this._x - 3;\r        }\r        else if (Key.getCode( ) == Key.RIGHT\r        {\r                this._x = this._x + 3;\r        }\r        else if (Key.getCode( ) == Key.UP)\r        {\r                this._y = this._y - 3;\r        }\r        else if (Key.getCode( ) == Key.DOWN)\r        {\r                this._y = this._y + 3;\r        }\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         {\rI’m new to AS and I still have alot to learn.\rThanks
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.
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 }
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