简体   繁体   English

Actionscript 3 中的“if (MouseEvent.CLICK = true)”错误?

[英]"if (MouseEvent.CLICK = true) " error in Actionscript 3?

These are the two errors;这是两个错误;

1067: Implicit coercion of a value of type Boolean to an unrelated type String. 1067:将类型 Boolean 的值隐式强制转换为不相关的字符串类型。

1049: Illegal assignment to a variable specified as constant. 1049: 对指定为常量的变量进行非法赋值。

I want to basically set it so, if mouse is click我想基本上设置它,如果鼠标被点击

the -y speed of symbol helicopter = variable 'speed'符号直升机的 -y 速度 = 变量“速度”

Any help?有什么帮助吗? Thanks谢谢

This test doesn't mean anything: MouseEvent.CLICK is a constant and its value is always "click" .这个测试没有任何意义: MouseEvent.CLICK是一个常量,它的值总是"click" So (MouseEvent.CLICK) will always be true (testing a string returns true if this string is not null).因此(MouseEvent.CLICK)将始终为true (如果字符串不为空,测试字符串将返回真)。

To check if the mouse is down, you should write something like that:要检查鼠标是否按下,您应该这样写:

var mouseDown:Boolean;
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);


function onMouseDown(event:MouseEvent):void
{
  mouseDown = true;
}

function onMouseUp(event:MouseEvent):void
{
  mouseDown = false;
}

function onEnterFrame(event:Event):void
{
  if (mouseDown)
  {
    helicopter.y += speed;
  }
  else
  {
    //maybe fall?
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM