as3.0 Mouse Keyboard is included in MC Monitor

Source: Internet
Author: User

scene to the MC and the scene respectively keyboard enter listening :
function Keyenter (event:keyboardevent): void {
  if (event.keycode==13) {
    switch (event.target) {
   & Nbsp;  case My_text:
        trace ("it");
         break;
      default:
        trace ("You Clicked Stage ");
        break;
    }

  
}
Stage.addeventlistener (Keyboardevent.key_down, keyenter);

Add the mouse monitor to the scene stage and MC separately :
function Testit (e:mouseevent): void {
Switch (e.target) {
Case My_text:
Trace ("You click my_text!");
Break
Case stage:
Trace ("You clicked stage!");
Break
}
}
Stage.addeventlistener (Mouseevent.click,testit);

to set the default focus in the stage :
Stage.focus=my_text;

If you want to make the MC effective. Need to add:
My_mc.buttonmode=true;

the keyboard enter key for the general MC listens on :
_pager_mc.addeventlistener (Keyboardevent.key_down, Keyenter);
Function Keyenter (event:keyboardevent): void {
  if (event.keycode==13) {
   & Nbsp;_pager_mc.removeeventlistener (Keyboardevent.key_down, Keyenter);
    trace ("it");
  }
}

Thanks for the help of Volcano brother. Learned A:
generally as long as the keyboard-related code, the direct test, you must remember to disable shortcut keys .
At the time of the test. On the control---"Disable shortcut key" before the tick.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.