Copy link to clipboard
Copied
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});
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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");
}
}
Copy link to clipboard
Copied
that is exactly what I needed! Do you think adobe will ever make an include-able library for the Boolean states of keyboard and mouse buttons?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now