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:
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;
}
}