Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 更改光标时,单击“无法识别”_Actionscript 3_Cursor_Adobe_Flash Cs5 - Fatal编程技术网

Actionscript 3 更改光标时,单击“无法识别”

Actionscript 3 更改光标时,单击“无法识别”,actionscript-3,cursor,adobe,flash-cs5,Actionscript 3,Cursor,Adobe,Flash Cs5,我目前正在用AdobeFlashCS5在AS3中编程一种点击游戏 每当我点击一扇门时,我都想检查一下钥匙是否握着以打开它。当从清单中选择键时,我希望光标不是原始光标,而是我与startDrag链接的特定光标,以获取键的图标 这是我的密码: var selectedKey:Boolean = false; key_obj.addEventListener(Mouse.CLICK, selectKey); door.addEventListener(Mouse.CLICK, openD

我目前正在用AdobeFlashCS5在AS3中编程一种点击游戏

每当我点击一扇门时,我都想检查一下钥匙是否握着以打开它。当从清单中选择键时,我希望光标不是原始光标,而是我与startDrag链接的特定光标,以获取键的图标

这是我的密码:

  var selectedKey:Boolean = false;

  key_obj.addEventListener(Mouse.CLICK, selectKey);
  door.addEventListener(Mouse.CLICK, openDoor);
  inventory_spot.addEventListener(Mouse.CLICK, drop);//send back key to inventory 


  function selectKey(e:MouseEvent):void
  {
    cursor.stopDrag();
    removeChild(cursor); //disable the old cursor style
    key_obj.removeEventListener(Mouse.CLICK, selectKey);
    key_obj.startDrag(true);
    selectedKey = true;

    addChild(inventory_spot);
  }

  function openDoor(e:MouseEvent):void
  {
    if (selectedKey)
      // open the door
    else
      // error : you don't have the key
  }

  function drop(e:MouseEvent):void
  {
    key_obj.stopDrag();
    key_obj.addEventListener(Mouse.CLICK, selectKey);
    selectedKey = false;
    addChild(cursor); // enable the old cursor
    cursor.startDrag(true);
    key_obj.x = inventory_spot.x [...] // position of the key in the inventory
    key_obj.y = inventory_spot.y [...]
    removeChild(inventory_spot);
  }
我的问题是:

当我用按键光标点击门时,什么也没有发生,实际上程序甚至没有调用openDoor,但一旦我把按键放回清单,并拿回旧的光标,openDoor就工作得很好

我不明白,函数不是仅仅因为我更改了光标而被调用的吗


感谢您的帮助

,因为单击可能指向您的按键光标,而不是门。要修复此问题,您需要将光标mouseEnabled=false和mouseChildren=false

我使用以下内容检查单击事件的传播。因此,在您的示例中,您可以检查最初单击的内容以及事件传播的位置。从不被称为问题通常是因为你认为被点击的东西不是

因此,添加以下内容:

stage.addEventListener(MouseEvent.CLICK,Functions.checkMouseEventTrail,false,0,true); 
称之为:

function checkMouseEventTrail($e:MouseEvent):void{
// displays the mouse event trail for any selected item
var p:* = $e.target;
trace("\nMOUSE EVENT TRAIL\n time: "+getTimer()+" type: "+$e.type+" target: "+$e.target.name+" cur target: "+$e.currentTarget);
var spacing:String="";
while (p){
    var curFrame = "none";
    if (p is MovieClip){curFrame = String(p.currentFrame);}
    trace(spacing+">>", p.name,": ",p+" vis: "+p.visible+" loc: "+p.x+","+p.y+" width: "+p.width+" height: "+p.height+" frame : "+curFrame+" class: "+getClassName(p));
    if (p != null){p = p.parent;}
    spacing+="  ";
}
trace("");
}


您将在输出中看到单击事件发生的情况。

您是对的,mouseEnabled=false解决了所有问题。我的key_obj光标的注册点是movieClip的中心,也许这就是为什么每次点击都会指向该键,而我的另一个自定义箭头状光标没有出现这个问题?不管怎样,问题解决了,谢谢