Skip to main content
thomasv24609185
Participant
August 8, 2015
Question

Why doesn't this work?

  • August 8, 2015
  • 2 replies
  • 502 views

function a(event:MouseEvent):void

{

while(MouseEvent.MOUSE_DOWN == true)

         {

          trace("the mouse is down.");

          }

}

stage.addEventListener(MouseEvent.MOUSE_DOWN, a);

It would be nice if action script had a boolean value set if the mouse button was up or down and would set a value to true or false that could be called

for example if the mouse button is down then mouseDown would be set to true else it would be set to false same thing for mouseUp.

Also it would be nice if we could make conditional statements inside of event listeners for conditionally calling a function based off events

var i:int;

i = 0;

stage.addEventListener(MouseEvent.CLICK, if(i == 0) { a});

This topic has been closed for replies.

2 replies

Inspiring
August 8, 2015

You can easily do everything you want.

var mouseIsDown:Boolean = false;

stage.addEventListener(MouseEvent.MOUSE_DOWN, md);

stage.addEventListener(MouseEvent.MOUSE_UP, mu);

addEventListener(Event.ENTER_FRAME, update);

function md(e:MouseEvent):void

{

     mouseIsDown = true;

}

function mu(e:MouseEvent):void

{

     mouseIsDown = false;

}

function update(e:Event):void

{

     if(mouseIsDown){

          trace("mouse is down");

     }

}

thomasv24609185
Participant
August 9, 2015

Ned Murphy
Legend
August 9, 2015

It is not likely they would do that with AS3, but as Dave shows, you can easily code it yourself and copy/paste as needed (or create a class of it) if your need for it is constant.

Ned Murphy
Legend
August 8, 2015

The mouse down and up events are single occurrence events, not enduring ones.  The events trigger on the action of pressing the mouse down or release, not the duration of that status after the event occurs.

You can create what you want yourself without much effort at all. Set up your own Booleans up that get set and reset by the mousedown/up event handling code.

I would not want the function you show processing at all as putting that while statement in place is not going to win you anything other than a likely crashing of Flash.