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

Go To StackoverFlow.com

1

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

2012-04-04 21:37
by Adzi
Isn't that supposed to be == in comparison instead of = operator - Mahesh 2012-04-04 21:38


4

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?
  }
}
2012-04-04 22:14
by Kodiak
Really helpful. thanks - Adzi 2012-04-24 16:52
You are welcome, please validate the answer - Kodiak 2012-04-25 07:46
Ads