For your issue, there are a few things I can point out:
1: You don’t need an Event.ENTER_FRAME event listener, as you aren’t even using it.
2: You seem to be trying to add an event listener (KeyboardEvent.KEY_DOWN) to the stage, at a point where the stage may not actually be accessible.
3: You are not type-casting your “MyKey” variable. It is good practice to do so (var MyKey:int = k.keyCode).
4: Although it is personal preference, naming all your functions and variables like “myKey” and “mainKeyboard” instead of “MyKey” and “MainKeyboard” usually looks cleaner and more readable (But is up to you).
5: Ensure you specify the type of object (or value) a function returns, try not to leave it blank. If your function does not return anything, use :void.
However your biggest problem is you have what I like to call a “if if if” problem. Lets run through your MainKeyboard function as if StageQuality is equal to StageQuality.HIGH (What it defaults to).
if(stage.quality==StageQuality.HIGH)
Well, this will be true, so we will now set stage.quality to LOW
if(stage.qualityStageQuality.LOW)
Well, this is going to be true now as well, so set the stage.quality to MEDIUM
if(stage.qualityStageQuality.MEDIUM)
Woah, this will be true too! So we now set the quality to
HIGH.
But, we are now back to where we started! Oops. To solve this problem, we can just add some simple “else if” statements.
View the full fix (Including my above suggestions) below: *Note, I changed some things. Notably I dont use the StageQuality class, as it doesn’t seem to work for me.
public class Main extends MovieClip {
public function Main() {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
private function init(e:Event=null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown,false,0,true);
}
public function keyDown(k:KeyboardEvent):void {
var myKey:int = k.keyCode;//MyKey = the pressed key
if (myKey == Keyboard.Q) {//81 is the number for Q, I think
if (stage.quality == "LOW") {
stage.quality = "MEDIUM";
} else if (stage.quality == "MEDIUM") {
stage.quality = "HIGH"
} else if (stage.quality == "HIGH") {
stage.quality = "LOW";
}
trace("New quality: " + stage.quality);
}
}
}
If you have any questions, feel free to PM me or post here again.