user3722298
user3722298

Reputation: 3

Flash ActionScript 3.0 button click over global MouseEvent.CLICK

I want do to the next one in flash with ActionScript 3.0:

  1. Global event (if user click in any part of the screen by mouse):

addEventListener (MouseEvent.CLICK, nextc);

function nextc (event:MouseEvent): void

{nextFrame();}

  1. Button event (if user click exact this button):

returnb54.addEventListener(MouseEvent.CLICK, returnb54a);

function returnb54a(event:MouseEvent):void

{prevFrame();}

But on the frame with this a global event and a button nothing happens when clicking the button.

Is there any way to prioritize button event over global?

Thank you.

Upvotes: 0

Views: 691

Answers (1)

gabriel
gabriel

Reputation: 2359

I created a very simple application to test your question (I'm using the same names as you defined, to be easier to understand).

I have changed 3 points:

1-

  this.stage.addEventListener (MouseEvent.CLICK, nextc);

2-

  function returnb54a(event:MouseEvent):void
  {
      event.stopImmediatePropagation();
      prevFrame();
  }

3-

  function nextc(event:MouseEvent): void
  {
     event.stopImmediatePropagation();
     nextFrame();
  }

The method: stopImmediatePropagation() prevents processing of any event listeners in the current node and any subsequent nodes in the event flow. This method takes effect immediately, and it affects event listeners in the current node. In contrast, the stopPropagation() method doesn't take effect until all the event listeners in the current node finish processing.

Try to implement these changes and see if will have the desired result.

Upvotes: 0

Related Questions