AS3 鼠标事件的另一种写法

2011-06-09 17:39:39 by 【6yang】, 399 visits, 收藏 | 返回

public class MouseEventExample extends MovieClip
{
 

 
   public function MouseEventExample() :void
   {
    m_mc.doubleClickEnabled = true;
    with (m_mc) {
     addEventListener(MouseEvent.CLICK, mouseEventHandler);
     addEventListener(MouseEvent.DOUBLE_CLICK, mouseEventHandler);
     addEventListener(MouseEvent.MOUSE_DOWN, mouseEventHandler);
     addEventListener(MouseEvent.MOUSE_UP, mouseEventHandler);
     addEventListener(MouseEvent.MOUSE_OVER, mouseEventHandler);
     addEventListener(MouseEvent.MOUSE_OUT, mouseEventHandler);
     addEventListener(MouseEvent.MIDDLE_CLICK, mouseEventHandler);
     addEventListener(MouseEvent.MOUSE_WHEEL, mouseEventHandler);
     addEventListener(MouseEvent.MIDDLE_MOUSE_DOWN, mouseEventHandler);
     addEventListener(MouseEvent.MIDDLE_MOUSE_UP, mouseEventHandler);
     addEventListener(MouseEvent.RIGHT_CLICK, mouseEventHandler);
     addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, mouseEventHandler);
     addEventListener(MouseEvent.RIGHT_MOUSE_UP, mouseEventHandler);
     addEventListener(MouseEvent.MOUSE_MOVE, mouseEventHandler);
    }
   }
  
   private function mouseEventHandler(event:MouseEvent):void {
    switch(event.type) {
     case MouseEvent.CLICK:
      trace("鼠标点击");
      break;
     case MouseEvent.DOUBLE_CLICK:
      trace("鼠标双击");
      break;
     case MouseEvent.MOUSE_DOWN:
      trace("鼠标左键被按下");
      break;
     case MouseEvent.MOUSE_UP:
      trace("鼠标左键弹起");
      break;
     case MouseEvent.MOUSE_OVER:
      trace("鼠标滑过");
      break;
     case MouseEvent.MOUSE_OUT:
      trace("鼠标滑出");
      break;
     case MouseEvent.MIDDLE_CLICK:
      trace("鼠标滑轮被按点击");
      break;
     case MouseEvent.MOUSE_WHEEL:
      trace("鼠标滑轮滚动");
      if(event.delta<0) {
       trace("鼠标滑轮向下滚动");
      }else if (event.delta > 0) {
       trace("鼠标滑轮向上滚动");
      }
      break;
     case MouseEvent.MIDDLE_MOUSE_DOWN:
      trace("鼠标滑轮被按下");
      break;
     case MouseEvent.MIDDLE_MOUSE_UP:
      trace("鼠标滑轮弹起");
      break;
     case MouseEvent.RIGHT_CLICK:
      trace("鼠标右键点击");
      break;

分享到:
share

    图片原图

    loading

    loading