Key.isDown trigger if statement only once

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