zoukankan      html  css  js  c++  java
  • 鼠标手势替换闪烁不停地问题

    2010-03-10 11:15

    今天为一个窗口写了个方法,大概意思是让target可以拖动ZSWindow,另外当鼠标移动到target上时,会有个十字拖动符号替换系统鼠标手势。可是我按下面做了后,发现changeMouseMark,stopMouseMark,dragWindow会不停地自动执行,然后鼠标也在那一直闪个不停。不知道为什么。

    代码
    1 public class ZSWindow extends Sprite
    2 {
    3
    4 public function ZSWindow(id:String){
    5 super();
    6 }
    7
    8 public function setMovetarget(target:DisplayObject):void{
    9 if(mouseMark==null){
    10 mouseMark = new DragMouse();
    11 mouseMark.visible = false;
    12 addChild(mouseMark);
    13 }
    14 moveTarget = target;
    15 moveTarget.addEventListener(MouseEvent.MOUSE_OVER,changeMouseMark);
    16 moveTarget.addEventListener(MouseEvent.MOUSE_DOWN,dragWindow);
    17 moveTarget.addEventListener(MouseEvent.MOUSE_OUT,stopMouseMark);
    18 }
    19
    20 private function dragWindow(event:MouseEvent):void{
    21 stage.addEventListener(MouseEvent.MOUSE_UP,stopDragWinddow);
    22 startDrag(false,new Rectangle(-_width+35,-_height+35,stage.stageWidth+_width- 70,stage.stageHeight+_height-70));
    23 event.updateAfterEvent();
    24 }
    25
    26 private function stopDragWinddow(event:MouseEvent):void{
    27 stopDrag();
    28 stage.removeEventListener(MouseEvent.MOUSE_UP,stopDragWinddow);
    29 }
    30
    31 private function changeMouseMark(event:MouseEvent):void{
    32 Mouse.hide();
    33 if(mouseMark.visible==false){
    34 mouseMark.visible = true;
    35 }
    36 stage.addEventListener(MouseEvent.MOUSE_MOVE,changeMousePosition);
    37 }
    38
    39 private function changeMousePosition(event:MouseEvent):void{
    40 mouseMark.x = mouseX;
    41 mouseMark.y = mouseY;
    42 setChildIndex(mouseMark,numChildren-1);
    43 event.updateAfterEvent();
    44 }
    45
    46 private function stopMouseMark(event:MouseEvent):void{
    47 Mouse.show();
    48 if(mouseMark&&mouseMark.visible){
    49 mouseMark.visible = false;
    50 }
    51 if(stage){
    52 stage.removeEventListener(MouseEvent.MOUSE_MOVE,changeMousePosition);
    53 }
    54 }
    55
    56 }
    57
    58  
    1 package com.zs.panel.com
    2 {
    3  import flash.display.Bitmap;
    4
    5 [Embed(source="com/assets/images/drag2.png")]
    6 public class DragMouse extends Bitmap
    7 {
    8 public function DragMouse()
    9 {
    10 super();
    11 }
    12 }
    13 }

    后来到天地会问了下,然后我在上面代码加上了mouseMark.mouseEnabled = false;之后就不闪烁了。

    问题所在:当我鼠标移动到moveTarget 上时,按理来说应该是系统鼠标手势被隐藏,替换的鼠标手势出现。但是,由于用来替换的鼠标手势的图片也能接收鼠标事件,moveTarget 就会执行moveTarget.addEventListener(MouseEvent.MOUSE_OUT,stopMouseMark);之后mouseMark被隐藏,鼠标焦点回到了moveTarget 上,之后mouseMark又出现,于是就闪烁不停。

    说明:mouseEnabled 属性可以使物件不再接收鼠标事件,mouseChildren属性可以使子项也不再接收鼠标事件。收益了!再次感谢!

  • 相关阅读:
    google code jam exercise——Your Rank Is Pure
    C/C++中的文件操作(2)
    google code jam exercise——File Fix It
    google code jam exercise——All Your Base
    C/C++中的文件操作(1)
    google code jam exercise——Center of Mass
    C/C++字符串操作split
    JavascriptDOM
    Javascript特权方法
    Report子报表
  • 原文地址:https://www.cnblogs.com/crkay/p/1747900.html
Copyright © 2011-2022 走看看