# Conditional Statements with Keyboard Events

**URL:** <https://forum.kirupa.com/t/conditional-statements-with-keyboard-events/292469>\
**Category:** flash\
**Created:** [July 14, 2009, 3:54pm UTC](https://forum.kirupa.com/t/conditional-statements-with-keyboard-events/292469 "2009-07-14T15:54:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanaali](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sanaali](https://forum.kirupa.com/u/sanaali)\
**Post date:** [July 14, 2009, 3:54pm UTC](https://forum.kirupa.com/t/conditional-statements-with-keyboard-events/292469/1 "2009-07-14T15:54:20Z")

</div>

I’m trying to load and unload UI Component based on the using pressing UP. When they press the UP key i want the UI component to load a specific image. When they press it again I want the image to be unloaded. And if they press it again I want it to be loaded again, etc…

Currently when I press the UP key it loads the image but it never unloads. I would really appreciate it if someone had any suggestions/help to make my code work. thanks in advance.

Here’s my current code:

```auto
var count:Number = 4;
var evenOrOdd:String;
if (count%2 != 0) {
evenOrOdd = "odd";
} else {
evenOrOdd = "even";
}

	stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
	function KeyPressed(evt:KeyboardEvent):void {
	switch (evt.keyCode) {
	case Keyboard.UP :
	if (evenOrOdd == "even") {
	loader.source = "C:/Users/alisan/Documents/FastBoot/stay_down.png";
	count++;
	trace("preboot");
	trace(count);
		} if (evenOrOdd == "odd") {
		loader.unload();
		count++;
		trace("windows");
	}
	break;
	}
	}

```
