# Problem with removing keyboard event from stage

**URL:** <https://forum.kirupa.com/t/problem-with-removing-keyboard-event-from-stage/244810>\
**Category:** flash\
**Created:** [November 21, 2007, 11:40pm UTC](https://forum.kirupa.com/t/problem-with-removing-keyboard-event-from-stage/244810 "2007-11-21T23:40:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karinger](https://avatars.discourse-cdn.com/v4/letter/k/e36b37/32.png) [@Karinger](https://forum.kirupa.com/u/Karinger)\
**Post date:** [November 21, 2007, 11:40pm UTC](https://forum.kirupa.com/t/problem-with-removing-keyboard-event-from-stage/244810/1 "2007-11-21T23:40:57Z")

</div>

I’m trying to write a function that, when the mouse rolls over a MovieClip object, if the user presses the up/down button, then the movie clip will climb/descend in the containers child list. In other words, if the mouse is on the object, and I press up, the target object should come forward in depth.

So far this is what I have:

```auto

myMovie.addEventListener(MouseEvent.ROLL_OVER, changeDepth);
myMovie.addEventListener(MouseEvent.ROLL_OUT, changeDepth);
                      
function changeDepth(e:MouseEvent) {[INDENT]var target = e.target;
trace(e.type);
var targDepth = container.getChildIndex(target);
var maxDepth = container.numChildren;
if (e.type == "rollOver") {[INDENT]stage.addEventListener(KeyboardEvent.KEY_UP, depthSwap);
[/INDENT]} else if(e.type == "rollOut"){[INDENT]stage.removeEventListener(KeyboardEvent.KEY_UP, depthSwap);
[/INDENT]}

function depthSwap(e:KeyboardEvent) {[INDENT]if (e.keyCode == 38) {[INDENT]if (targDepth+1<maxDepth) {[INDENT][INDENT]container.setChildIndex(target,targDepth+1);
[/INDENT][/INDENT]} else if (e.keyCode == 40) {[INDENT] if (targDepth>1) {[INDENT]container.setChildIndex(target,targDepth-1);
[/INDENT]}
[/INDENT]}
[/INDENT]}
[/INDENT]}
[/INDENT]}

```

My issue is that the KeyboardEvent still fires off when I roll out of my target MovieClip… (May of had some braces get unbalanced while copy pasting)  
:h:
