Skip to main content
Inspiring
August 21, 2012
Question

MouseEvent.MOUSE_MOVE listener won't remove

  • August 21, 2012
  • 4 replies
  • 779 views

Hey All,

So this is an event chain issue. I'll try to discribe it best I can. I'm going to have to put a work around in for now but here it goes.

I have an object called scroller. Scroller moves in either a horizontal or vertial direction. Scroller can container other scrollers as children up to one depth and moving in the opposite direction as the parent.

Scrollers can only move in one direction at a time and require the user to MouseUp and MouseDown to re-engage direction lock.

Direction lock is determined via the greater displacement of X over Y from the Origin point.

Displacement checking runs on both objects but starts at the child of the chain.

1.) Child.MOUSE_MOVE 

2.) Parent.MOUSE_MOVE   

If the childs fires the direction lock first. The parent gets and event to stop displacement checking.

Child.MOUSE_MOVE;

Child.dispatchEvent(Parent.STOP_CHECKING)

Parent.removeEventListener(MOUSE_MOVE)

Parent.MOUSE_MOVE;

If you notice from the above the parent still listens for the MouseMove event. It took a while to figure out that the removeEventListener does not actually work. At first I thought the events were doubled up somehow even though AS3 doesn't really allow for that anymore but the following created an endless loop and that's when I realized the listener would not be removed.

while(Parent.hasEvent(MOUSE_MOVE))

   Parent.removeEventListener(MOUSE_MOVE)

Is this a bug or does it have something to do with the Parents.MOUSE_MOVE already being queued in the event chain of things? I can see that happening but I don't know why the listener would not be able to be removed. I'm also planning on creating a bug ticket but I figure I'd ask here because more people respond to these.

This topic has been closed for replies.

4 replies

Nimisha1
Participating Frequently
August 24, 2012

Hi Pete,

Please log a bug with sample source files so that we track this issue.

Thanks,

Nimisha

Inspiring
August 24, 2012

Should already be one.

Mark.fromOP
Inspiring
August 25, 2012

Pete what about using a boolean to determine which event should fire.

Lets say

var touchBegingOnChild:Boolean (btw impossible to write this variable without sounding like a child molester)

add a TOUCH_BEGIN listener

so if the user begins the touch on a child scroller then set the variable touchBeginOnChild to true and if they begin the touch on the parent scroller then set the variable to false then your TOUCH_MOVE should properly react to whatever is happening.

add general TOUCH_MOVE listener but wrap it all in an if statement

if (touchBegingOnChild == true)

{

//do whatever you do to the child scrollers

}

if (touchBegingOnChild == false)

{

//do whatever you do to the parent scroller

}

Another option is to get rid of the whole level business child vs parent and set a background layer to act as a parent, so in reality you have a bunch of children objects wrapped inside a commmon movie clip but if the user touches the background layer and not one of the scrollers then interact with the entrie MC on the TOUCH_MOVE related function otherwise if they touch one of the scrollers then deal with those.

Hope that makes some sense.