# Multiple Keypress Focus

**URL:** <https://forum.kirupa.com/t/multiple-keypress-focus/310858>\
**Category:** flash\
**Created:** [June 21, 2010, 3:31pm UTC](https://forum.kirupa.com/t/multiple-keypress-focus/310858 "2010-06-21T15:31:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidj51](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@davidj51](https://forum.kirupa.com/u/davidj51)\
**Post date:** [June 21, 2010, 3:31pm UTC](https://forum.kirupa.com/t/multiple-keypress-focus/310858/1 "2010-06-21T15:31:45Z")

</div>

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");  
}  
}  
}
