Adzi
Adzi

Reputation: 47

"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.

1049: Illegal assignment to a variable specified as constant.

I want to basically set it so, if mouse is click

the -y speed of symbol helicopter = variable 'speed'

Any help? Thanks

Upvotes: 1

Views: 3213

Answers (1)

Kodiak
Kodiak

Reputation: 5978

This test doesn't mean anything: MouseEvent.CLICK is a constant and its value is always "click". So (MouseEvent.CLICK) will always be true (testing a string returns true if this string is not null).

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?
  }
}

Upvotes: 4

Related Questions