I don't know if this will help, but I had a requirement for a hover
behaviour, so I implemented the following:

package {

        import flash.events.FocusEvent;
        import flash.events.MouseEvent;
        import flash.events.TimerEvent;
        import flash.utils.Timer;
        
        import mx.core.UIComponent;
        import mx.events.MoveEvent;
        
        import org.osflash.signals.Signal;

        public class HoverMonitor {

                private var _target:UIComponent;

                private var _timer:Timer;

                private var _active:Boolean;

                private var _hovering:Boolean;

                private var _stilltime:int;

                private var _sensitivity:int;

                private var _lastX:int;

                private var _lastY:int;

                private var _hoverX:int;

                private var _hoverY:int;
                
                private var _id:String;

                public var onHover:Signal;

                public function HoverMonitor(target:UIComponent, id:String)
{
                        _target = target;
                        _active = false;
                        _hovering = false;
                        _id = id;
                        onHover = new Signal;
                }

                public function activate(sensitivity:int = 5 , stilltime:int
= 300):void {
                        _target.addEventListener(MouseEvent.MOUSE_MOVE ,
onMove);
                        _target.addEventListener(MouseEvent.MOUSE_OUT ,
onMouseLeave);
                        _active = true;
                        _hovering = false;
                        _sensitivity = sensitivity;
                        _stilltime = stilltime;
                        _timer = new Timer(_stilltime , 1)
                        _timer.addEventListener(TimerEvent.TIMER , onTimer);
                }

                public function deactivate():void {
                        _target.removeEventListener(MouseEvent.MOUSE_MOVE ,
onMove);
                        _target.removeEventListener(MouseEvent.MOUSE_OUT ,
onMouseLeave);
                        _hovering = false;
                        _active = false;
                        _timer.stop();
                        _timer.removeEventListener(TimerEvent.TIMER ,
onTimer);
                        _timer = null;
                }

                protected function onMove(event:MouseEvent):void {
                        if (_active) {
                                _timer.reset();
                                if (_hovering) {
                                        if (Math.abs(_hoverX - event.localX)
> _sensitivity || Math.abs(_hoverY - event.localY) > _sensitivity) {
                                                _hovering = false;
                                                onHover.dispatch({hovering:
false , x: _lastX , y: _lastY, id: _id});
                                        }
                                }
                                _lastX = event.localX;
                                _lastY = event.localY;
                                _timer.start();
                        }
                }

                protected function onMouseLeave(event:MouseEvent):void {
                        if (_active) {
                                _timer.reset();
                                if (_hovering) {
                                        onHover.dispatch({hovering: false ,
x: _lastX , y: _lastY, id: _id});
                                }
                                _hovering = false;
                                _lastX = event.localX;
                                _lastY = event.localY;
                        }
                }

                protected function onTimer(event:TimerEvent):void {
                        if (_active) {
                                _hovering = true;
                                _hoverX = _lastX;
                                _hoverY = _lastY;
                                onHover.dispatch({hovering: true , x:
_hoverX , y: _hoverY, id: _id});
                        }
                }

        }
}


In actionscript, assuming you have a uicomponent (myButton) defined:

var hvr:HoverMonitor = new HoverMonitor( myButton, "myButton" );
hvr.onHover( function ( o:Object ) : void
{
        trace(o['hovering'],o['x'],o['y'],o['id']);
});
hvr.activate( 0, 1000); // dead stop for 1 second

It uses as3sginals, but could easily be modified to use an event.

Comments are  welcome ( yes, I know the code could be better commented ).

-----Original Message-----
From: Gary Young [mailto:[email protected]] 
Sent: 2013-12-25 22:59 PM
To: [email protected]
Subject: Re: Understand when mouse stop

Please don't add such an event into Flex code, it's just not a part of Flex.

-Gary


On Wed, Dec 25, 2013 at 9:57 PM, Gary Young <[email protected]> wrote:

> There's no way to know when it's stopped, because you can't define it 
> clearly, the only way to define it is to set an interval during which 
> there's no MouseMove event dispatched, then dispatch a MouseStopped, 
> but if you set the interval too small, every MouseMove will have a
MouseStop event.
>
>
> I think use EnterFrameEvent will be practical, if there was any 
> MouseMove in last frame and none the next frame, treat it as a MouseStop.
>
>
>
>
> On Tue, Dec 24, 2013 at 5:15 PM, Alex Harui <[email protected]> wrote:
>
>> Enter_frame gets dispatched all the time.  There's no way to 
>> immediately know if the mouse is "stopped".  The user could move the 
>> mouse at the very moment you check.  You pretty much have to wait for
some amount of time to
>> see if there is another mouseMove or not.   The SystemManager dispatches
>> an "idle" event when there is no input for 1 second.  Is that what 
>> you want?
>>
>> http://help.adobe.com/en_US/FlashPlatform//reference/actionscript/3/m
>> x/mana 
>> gers/SystemManager.html#event:idle<http://help.adobe.com/en_US/FlashP
>> latform//reference/actionscript/3/mx/managers/SystemManager.html#even
>> t:idle>
>>
>> On 12/24/13 7:03 AM, "oscaroxy" <[email protected]> wrote:
>>
>> >Do exist a event/method in order to understand when mouse stop?
>> >I use move mouse event and I would run a method after move mouse 
>> >event
>> and
>> >when the mouse's stopped!
>> >I tried by enter_frame, but the method run more that one time...
>> >thanks
>> >
>> >
>> >
>> >--
>> >View this message in context:
>> >
>> http://apache-flex-users.2333346.n4.nabble.com/Understand-when-mouse-
>> stop-
>> >tp4283.html
>> >Sent from the Apache Flex Users mailing list archive at Nabble.com.
>>
>>
>



-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4259 / Virus Database: 3658/6949 - Release Date: 12/25/13

Reply via email to