Skip to main content
Participating Frequently
September 1, 2013
Answered

Multiple Button MouseEvent Listeners not working in continuation in as3?

  • September 1, 2013
  • 2 replies
  • 2079 views

Hi,

I've multple buttons following this drag structure to scale in different direction various corners of the rectangle:

scale_bottomRight.addEventListener(MouseEvent.MOUSE_DOWN,scaleBottomRight_Start);

function scaleBottomRight_Start(mEvent:MouseEvent):void

{

/*code*/

          mEvent.target.startDrag(true,new Rectangle(scale_bottomRight.x,scale_bottomRight.y,100,100));

          addEventListener(Event.ENTER_FRAME, update_BottomRight);

}

function update_BottomRight(event:Event):void

{

/*code*/

}

  scale_bottomRight.addEventListener(MouseEvent.MOUSE_UP, scalebottomRight_Stop);

  function scalebottomRight_Stop(event:MouseEvent):void

{

            event.target.stopDrag();

  event.target.buttonMode = false;

}

scale_bottomRight.buttonMode = true;

However, after the dragging few buttons, other drag buttons don't work and first button flickers ....... i think not removing eventListeners is the problem.... can anyone guide me what i may be doing wrong and if remove eventListener is the problem, do i need to call them on EXIT_FRAME function (as i don't have one) or within somewhere else?

This topic has been closed for replies.
Correct answer kglad

add a stage listener for the mouseup event in your mousedown listener function.  use it to call a function where you remove your enterframe listener and remove the stage listener.

2 replies

Inspiring
September 1, 2013

Try this:

scale_bottomRight.buttonMode = true;

scale_bottomRight.addEventListener(MouseEvent.MOUSE_DOWN, scaleBottomRight_Start);

function scaleBottomRight_Start(e:MouseEvent):void

{

          e.target.startDrag(true, new Rectangle(scale_bottomRight.x, scale_bottomRight.y, 100, 100));

          stage.addEventListener(MouseEvent.MOUSE_UP, scalebottomRight_Stop);

          addEventListener(Event.ENTER_FRAME, update_BottomRight);

}

function update_BottomRight(e:Event):void

{

/*code*/

}

function scalebottomRight_Stop(e:MouseEvent):void

{

          stopDrag();

          stage.removeEventListener(MouseEvent.MOUSE_UP, scalebottomRight_Stop);

          removeEventListener(Event.ENTER_FRAME, update_BottomRight);

          e.target.buttonMode = false;

}

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 1, 2013

add a stage listener for the mouseup event in your mousedown listener function.  use it to call a function where you remove your enterframe listener and remove the stage listener.

maulshreAuthor
Participating Frequently
September 1, 2013

thanks... this seems to work ... however, it is adding another problem that even after mouse_UP, while rectangle stops scaling and moving, my button keeps on moving until i hit another click on the button... how to solve it?

kglad
Community Expert
Community Expert
September 1, 2013

apply your stopDrag when the stage detects a mouseup.