About

<#TEMPLATE_INCLUDE_NINEPAGE_ABOUTME#>
  • Nov

    9

    表找了,没错,AS3里没有这三个事件。但可以基于 MouseEvent 事件以及它的 buttonDown 属性来模拟这三个自定义事件: 

    var button:Sprite = new Sprite();
    button.graphics.beginFill(0x000000, 1);
    button.graphics.drawRect(50,50,200,100);
    addChild(button);
    button.buttonMode = true;
    button.addEventListener(MouseEvent.MOUSE_DOWN, buttonPress);
    button.addEventListener(MouseEvent.MOUSE_UP, buttonRelease);
    button.addEventListener(MouseEvent.MOUSE_OVER, buttonOver);
    button.addEventListener(MouseEvent.MOUSE_OUT, buttonOut);
    function buttonPress(e:MouseEvent):void {
     trace('onPress');
     button.parent.stage.addEventListener(MouseEvent.MOUSE_UP, buttonRelease);
    }
    function buttonRelease(e:MouseEvent):void {
     button.parent.stage.removeEventListener(MouseEvent.MOUSE_UP, buttonRelease);
     if (e.currentTarget != button) {
      trace('onReleasedOutside');
     } else {
      trace('onRelease');
     }
    }
    function buttonOver(e:MouseEvent):void {
     if (e.buttonDown) {
      trace('onDragOver');
     } else {
      trace('onRollOver');
     }
    }
    function buttonOut(e:MouseEvent):void {
     if (e.buttonDown) {
      trace('onDragOut');
     } else {
      trace('onRollOut');
     }
    }

    原文出处:http://www.scottgmorgan.com/blog/index.php/2007/12/20/ondragover-ondragout-and-onreleaseoutside-in-as3/