# Key.isDown trigger if statement only once

**URL:** <https://forum.kirupa.com/t/key-isdown-trigger-if-statement-only-once/202855>\
**Category:** Uncategorized\
**Created:** [October 5, 2006, 11:10am UTC](https://forum.kirupa.com/t/key-isdown-trigger-if-statement-only-once/202855 "2006-10-05T11:10:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![VDG](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@VDG](https://forum.kirupa.com/u/VDG)\
**Post date:** [October 5, 2006, 11:10am UTC](https://forum.kirupa.com/t/key-isdown-trigger-if-statement-only-once/202855/1 "2006-10-05T11:10:40Z")

</div>

Hi,

I’m trying to add arrow key control to my image gallery to increment and decrement the image number, but if I go to another section and go back to the gallery, the incrementing is doubled, so that I step through the images by two’s. If I repeat this, it always adds 1. Here’s the code I have for the Arrow keys:

```
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#000000] **var** [/COLOR] keyListener:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]Object[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];

```

keyListener.[COLOR=#0000FF]onKeyDown[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]cur == [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
cur = totImg;  
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]  
cur–;  
[COLOR=#000000]}[/COLOR]  
loadPicCOLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]cur\>=[COLOR=#000080]1[/COLOR] && cur != totImg[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
cur++;  
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]  
cur = [COLOR=#000080]1[/COLOR];  
[COLOR=#000000]}[/COLOR]  
loadPicCOLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR];  
[COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]addListener[/COLOR]COLOR=#000000[/COLOR];  
[/LEFT]  
[/FONT]

Any idea how I would remove the listener in the correct way?

Thanks,

VDG
