Question

I am currently working with a drawing tool for a mapping API, and every time I double-click the mouse a map service will perform a measurement and display the length of the line that I am drawing.

I want to mimic this double-click manually by dispatching a MouseEvent.DOUBLE_CLICK, but the map service is not listening to this default Flex event. I suspect that the API has created a custom MapMouseEvent or something like it that is being dispatched when a user double-clicks the mouse.

Is there a way to determine which event is being dispatched when I double-click the mouse?

Was it helpful?

Solution

The API isn't necessarily dispatching its own event. Even if it is, it has to listen for MouseEvents first. One could detect double-clicks using MouseEvent.DOUBLE_CLICK, or by listening for successive MouseEvent.CLICK or MouseEvent.MOUSE_DOWN events. There's no way (just within Flash) to detect a double click without listening for one or more of those events somewhere.

It's also possible that the Map Service IS listening for the DOUBLE_CLICK event, but you're not dispatching the MouseEvent from the right object. For example, if the map service does this:

mapRoot.mapChild.addEventListener(MouseEvent.DOUBLE_CLICK, performMeasurement);

and you do this:

mapRoot.dispatchEvent(new MouseEvent(MouseEvent.DOUBLE_CLICK));

nothing is going to happen.

There are other possibilities as well:
When you actually perform a double-click with the mouse, you cause several events to be dispatched: MOUSE_DOWN, MOUSE_UP, CLICK, MOUSE_DOWN, MOUSE_UP, CLICK, DOUBLE_CLICK

It's possible that the map service listens for MOUSE_DOWN, and adds the DOUBLE_CLICK listener inside the MOUSE_DOWN handler, like this:

mapRoot.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDownHandler);

private function _mouseDownHandler(event:MouseEvent):void
{
    var targ:InteractiveObject = event.target as InteractiveObject;
    targ.addEventListener(MouseEvent.DOUBLE_CLICK, _doubleClickHandler);
}

private function _doubleClickHandler(event:MouseEvent):void
{
    var targ:InteractiveObject = event.target as InteractiveObject;
    targ.removeEventListener(MouseEVent.DOUBLE_CLICK, doubleClickHandler);
    performMeasurement();
}

So you may actually need to dispatch a combination of events to trigger the handler.


You can try the following:

Use DisplayObjectContainer.getObjectsUnderPoint() to get an Array of all the objects that could be responding to the click. Then from each of the objects in that array, try dispatching various sequences of MouseEvents till you come up with the right event(s) from the right object.

Take note though, that if areInaccessibleObjectsUnderPoint() returns true for the point you test at, then there are some objects you won't be able to get access to, and if those are the ones the map service is listening to, then you're out of luck.

OTHER TIPS

public function cbMouseEvents( e:MouseEvent ):void{
    trace( e.type )
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top