I want to be able to toggle images on and off on key press.
I cannot get multiple keys to work. I used to do this in Flash MX with the code placed on buttons off the stage. I used tell targeting with movie clips on the stage that had blank first frames and images on the second frame. Each button would call the second frame of a movie clip on keypress.
Below is the code that is not working in AS3/CS4 - “M1” and “M2” are the two test movies, but only M1 works.
Anyone have an idea how to do this correctly? Thanks.
stop();
stage.focus=M1_mc
M1_mc.focusRect = false;
M1_mc.addEventListener(KeyboardEvent.KEY_DOWN, keyReveal001);
M1_mc.movieState = “M1”;
function keyReveal001(keyEvent:KeyboardEvent) {
if (keyEvent.keyCode == 65) {
M1_mc.gotoAndStop(M1_mc.movieState+" on");
} else {
if (keyEvent.keyCode == 65) {
M1_mc.gotoAndStop(M1_mc.buttonState+" off");
}
}
}
M2_mc.focusRect = false;
M2_mc.addEventListener(KeyboardEvent.KEY_DOWN, keyReveal002);
M2_mc.movieState = “M2”;
function keyReveal002(keyEvent:KeyboardEvent) {
if (keyEvent.keyCode == 66) {
M2_mc.gotoAndStop(M2_mc.movieState+" on");
} else {
if (keyEvent.keyCode == 66) {
M2_mc.gotoAndStop(M2_mc.buttonState+" off");
}
}
}