0
votes

I'am drag game scene in Flash project (mouse down - start drag, mouse up - stop drag). If I mouse up outside stage, click on any object (buttons) don't work once. After one click other click works fine. What's wrong?

update: Trace logs shown that there event as mouseOver, mouseDown, mouseUp, mouseOut are dispatches, but not CLICK.

update: There is silencer of first click after drag in the project. It's necessary to eliminate situation of end drag on some game object (dispath click). Sorry. Thank you all for answers.

2

2 Answers

1
votes

You might be losing focus when leaving the stage. Try using (Event.MOUSE_LEAVE) to 'force' a mouse_up.

1
votes

something like this:

private var _draggedItem:Sprite;

myDisplayObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

private function mouseDownHandler(event:MouseEvent):void {
    _draggedItem = event.currentTarget as Sprite;
    _draggedItem.startDrag();
    _draggedItem.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    stage.addEventListener(Event.MOUSE_LEAVE, stageMouseOutHandler);
}

private function stopDragCurrentItem():void {
    if (_draggedItem) {
        _draggedItem.stopDrag();
        _draggedItem.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
        if (stage) {
            stage.removeEventListener(Event.MOUSE_LEAVE, stageMouseOutHandler);
        }
        _draggedItem = null;
    }
}

private function mouseUpHandler(event:MouseEvent):void {
    stopDragCurrentItem();
}

private function stageMouseOutHandler(event:Event):void {
    trace("stage out!")
    stopDragCurrentItem();
}

update: And concerning the lost focus, you cold do the following in html where you embed your flash:

 <object classid="..." codebase="...." width=550 height=400 
         name="myMovie" onmouseover="window.document.myMovie.focus();">

though i haven't tested it.