Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why doesn't this work?

Community Beginner ,
Aug 08, 2015 Aug 08, 2015

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});

TOPICS
ActionScript
480
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2015 Aug 08, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 08, 2015 Aug 08, 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");

     }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 09, 2015 Aug 09, 2015

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 09, 2015 Aug 09, 2015
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines