16

Event.MOUSE_LEAVEは Actionscript 3 で優れていますが、ユーザーがマウスの左ボタン (または右ボタン) を押したままにしている場合は起動しないようです。

マウスを押したままマウスが Flash ムービーから離れたかどうかを検出する方法はありますか? それともフラッシュムービー以外で公開すれば?

4

8 に答える 8

2

陥ってはいけないいくつかのトリッキーなトラップを次に示します。

奇妙なことの 1 つは、Chrome + Firefox では、または の WMODE に対して MOUSE_LEAVE イベントが送出されないことです。起動しません-マウスを上下に動かします。OPAQUETRANSPARENT

それは正常にWINDOW動作します。それを見つけるのに長い時間がかかりました!詳細... http://bugs.adobe.com/jira/browse/FP-892


次に、 ではなく、ハンドラーEventのパラメーターの型に使用していることを確認してください。で処理しようとすると、表示されないエラーが発生します (デバッグ フラッシュ プレーヤーを使用している場合を除く)。おそらく他のすべてのハンドラーが同じメソッドを指しているため、これは非常に簡単な間違いです。Event.MOUSE_LEAVEMouseEventMOUSE_LEAVEe:MouseEvent

endDragこれが私がしていることです:(から私のメインを呼び出すだけですmouseLeave(e:Event)

stage.addEventListener(MouseEvent.MOUSE_MOVE, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, endDrag);
stage.addEventListener(Event.DEACTIVATE, endDrag);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave);

private function mouseLeave(e:Event):void
{
    endDrag(new MouseEvent("MOUSE_LEAVE"));
}

public function endDrag(evt:MouseEvent):void
{
    /// handle end drag
}
于 2011-05-18T19:56:09.757 に答える
1

Flex アプリケーションに組み込まなければならなかった PDF タイプのビューアでも、同様の問題が発生しました。マウスがステージやブラウザ ウィンドウから離れても、パン機能が機能するようにしたかったのです。これをどのように達成したかを次に示します。Flex Framework クラスへの参照を削除するようにコードを変更したので、これはどの AS3 プロジェクトにも適用できるはずです。タイマーでこれらmouseDownの値の追跡を開始します。 ターゲット ステージの_client任意の値にすることができます。flash.display.DisplayObject私の場合はFlexmx.controls.SWFLoaderオブジェクトでしたが、あなたの場合はドラッグターゲットになると思います:

private function get currentMouseX():Number
{
     return _client.stage.mouseX; 
}

private function get currentMouseY():Number
{
     return _client.stage.mouseY; 
}

stage.mouseXとのstage.mouseY値は、マウスがステージ内にあるか、ブラウザー ウィンドウ内にあるかに関係なく、ステージに対して相対的に定義されます (少なくとも Flash Player 10 では、以前のバージョンの Flash Player ではテストしていません)。マウスがステージの外にあるかどうかを確認するには、次のようにテストして、これらの値がステージ内にあるかどうかを確認します。

if (currentMouseY < 0 || 
    currentMouseY > _client.stage.height || 
    currentMouseX < 0 || 
    currentMouseX > _client.stage.width)
{
     // Do something here
}

追記:ステージ外でのイベント検知mouseUpについてですが、ステージ上にリスナーを登録しておけば、ステージ外やブラウザ外でイベントが発生してもmouseUpが発生します。参照用にイベント関数を処理する方法のコードを次に示します。_clientオブジェクトは次のいずれかflash.display.DisplayObjectです。

 // attach the events like so when you initialize
 _client.addEventListener(MouseEvent.MOUSE_DOWN  , handleMouse);   
 _client.addEventListener(MouseEvent.MOUSE_OUT   , handleMouse);
 _client.addEventListener(MouseEvent.MOUSE_OVER  , handleMouse);
//

// and handle them like this:
 private function handleMouse(e:MouseEvent):void
 {
      switch(e.type)
      {

          case "mouseDown":

         // add listeners, notice the mouse move and mouse up are 
         // attached to the stage, not the display object this way
         // events are issued regardless of whether the mouse is in 
         // the stage or even within the browser window

         _client.stage.addEventListener(MouseEvent.MOUSE_UP, handleMouse);
         _client.addEventListener(MouseEvent.CLICK, handleMouse);      
         _client.stage.addEventListener(MouseEvent.MOUSE_MOVE, handleMouse);    


         // remove listeners     
         _client.removeEventListener(MouseEvent.MOUSE_DOWN, handleMouse); 

         //
         // commands / actions 

         break;


         case "mouseUp":

         // add listeners
        _client.addEventListener(MouseEvent.MOUSE_DOWN, handleMouse); 


         // remove listeners 
         _client.stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouse);
         _client.stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleMouse);    


         // commands/actions 

         break;


         case "click":


         // add listeners
         _client.addEventListener(MouseEvent.DOUBLE_CLICK, handleMouse);


         // remove listeners    
         _client.removeEventListener(MouseEvent.CLICK, handleMouse); 


         // commands / actions

         break;

         case "mouseMove":

         // add listeners


         // remove listeners
         _client.stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleMouse);
         _client.removeEventListener(MouseEvent.CLICK, handleMouse);   


         // commands 

         break;

         case "mouseOut":

         // add listeners


         // remove listeners

         // commands / actions

         break;

         case "mouseOver":

         // add listeners


         // remove listeners


         // commands /actions

         break;
     }
 }

編集: Flex フレームワーク クラスへの参照を削除しました 編集: Mac OSX の Safari ブラウザーでアプリケーションを実行すると、ブラウザー ウィンドウの外側のイベントに問題が発生する可能性があることを覚えています。このコードを使用する場合は、そのブラウザで必ずテストしてください。これは私のアプリケーションの問題ではなかったので、これ以上問題を調査しませんでした。

于 2009-11-07T01:45:09.437 に答える
0

マウスを押したままマウスが Flash ムービーから離れたかどうかを検出する方法はありますか?

私が知っていることではない

それともフラッシュムービー以外で公開すれば?

外部にリリースすると、Event.MOUSE_LEAVE が発生します。

詳細はこちら http://blog.zupko.info/?p=3 JIMISAACS のコメントを参照してください。

于 2009-10-14T23:03:42.403 に答える
0

これが正しい答えです。DisplayObject を渡すカスタム クラスで、マウスアップまたはマウス アウト オブ ステージまでドラッグします。自由にカスタマイズ:

package fanlib.gfx
{
    import flash.display.DisplayObject;
    import flash.display.Stage;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import flash.ui.Mouse;

    public class Drag
    {
        private var obj:DisplayObject;
        private var point:Point = new Point();
        private var stg:Stage;

        public function Drag(obj:DisplayObject)
        {
            this.obj = obj;
            stg = Stg.Get();
            stg.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
            stg.addEventListener(MouseEvent.MOUSE_UP, stopDrag);
            //stg.addEventListener(Event.MOUSE_LEAVE, stopDrag); // sh*t just won't fire
            point.setTo(stg.mouseX, stg.mouseY);
        }

        private function mouseMove(e:MouseEvent):void {
            if (stg.mouseX <= 0 ||
                stg.mouseY <= 0 ||
                stg.mouseX >= stg.stageWidth ||
                stg.mouseY >= stg.stageHeight) {
                stopDrag();
                return;
            }
            obj.x += stg.mouseX - point.x;
            obj.y += stg.mouseY - point.y;
            point.setTo(stg.mouseX, stg.mouseY);
        }

        public function stopDrag(e:* = null):void {
            stg.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
            stg.removeEventListener(MouseEvent.MOUSE_UP, stopDrag);
            //stg.removeEventListener(Event.MOUSE_LEAVE, stopDrag);
        }
    }

}
于 2014-11-20T17:53:10.830 に答える
0

MovieClip をドラッグしている場合、これはうまく機能するようです。

stage.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);

編集 - 気にしない

于 2009-10-13T23:08:41.583 に答える
0
    var youMax_X:Number; //set this var to Max x
    var youMax_Y:Number; //set this var to `enter code here`Max y

    var dragBounds:Rectangle = new Rectangle(0,0,youMax_X,yourMax_Y);

    stage.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
    stage.addEventListener(MouseEvent.MOUSE_UP,handleUp);


    private function handleDown(e:Event):void{
            this.startDrag(false,dragBounds);
    }
    private function handleUp(e:Event):void{
        this.stopDrag();
    }
于 2011-09-28T12:12:07.593 に答える