2
* This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
9
import neash.events.Event;
11
import flash.events.Event;
12
import flash.events.MouseEvent;
18
* Use this to add global handlers since otherwise it is annoyting to try
19
* and wait for the stage in an added function to add these handlers.
21
static public function addListener<T>( evt : String, func : T -> Void, ?priority : Null<Int> )
23
if( priority == null )
26
neash.Lib.current.stage.addEventListener( evt, func,false, priority, true /*weak*/ );
28
flash.Lib.current.stage.addEventListener( evt, func,false, priority, true /*weak*/ );
32
static public function removeListener<T>( evt : String, func : T -> Void )
35
neash.Lib.current.stage.removeEventListener( evt, func );
37
flash.Lib.current.stage.removeEventListener( evt, func );
41
static public function dispatch( evt : Event )
44
neash.Lib.current.stage.dispatchEvent( evt );
46
flash.Lib.current.stage.dispatchEvent( evt );
51
* Does the current VM support the ADDED_TO_STAGE and
52
* REMOVED_FROM_STAGE events.
54
static public function supportsAddedToStage() : Bool
60
if( _supportsAddedToStage == null )
61
_supportsAddedToStage = system.Version.checkFlashVersion( "9.0.28" );
62
return _supportsAddedToStage;
65
//cache the result since it is called often by AnimatedWidget, and perhaps others
66
static var _supportsAddedToStage : Null<Bool>;
69
static var captureMouseEvents = [
70
MouseEvent.MOUSE_DOWN, MouseEvent.MOUSE_UP,
71
MouseEvent.CLICK, MouseEvent.DOUBLE_CLICK,
72
MouseEvent.MOUSE_WHEEL,
73
MouseEvent.MOUSE_MOVE, MouseEvent.MOUSE_OVER, MouseEvent.MOUSE_OUT,
74
MouseEvent.ROLL_OUT, MouseEvent.ROLL_OVER
78
* Captures all mouse events and redispatches them to the provided object.
79
* This is a true capture, dispatching is then stopped in the main flow.
81
* NOTE: there are some potential caveats to how this works, to avoid them the
82
* receiver should follow these rules:
83
* * Not dispatch an event subject to the capture
84
* * call endCapture as soon as possible
85
* * not change the display tree
87
* TODO: make Modal use this system, though heed warning about somethign wrong
88
* with capturing some mouse events
90
static public function captureMouse( no : NativeObject )
92
capture( no, captureMouseEvents );
95
static var captureNO : NativeObject;
96
static var captureEvents : Array<String>;
97
static public var captureContProp : Bool; //continue propogation of the current event
99
static function capture( no : NativeObject, events : Array<String> )
101
ASSERT_NULL( captureNO );
103
captureEvents = events;
105
for( evt in captureEvents )
106
flash.Lib.current.stage.addEventListener( evt, propagateEvent, true );
108
//TODO: watch for object being removed and stop the capture
111
static public function endCapture( no : NativeObject )
113
ASSERT( no == captureNO );
116
for( evt in captureEvents )
117
flash.Lib.current.stage.removeEventListener( evt, propagateEvent, true );
120
//used to stop the infinite recursion caused by the redispatch of the event
121
static var inCapture : Bool = false;
122
static function propagateEvent( evt : Event )
124
if( inCapture || !captureNO.hasEventListener( evt.type ) )
128
captureContProp = false;
129
captureNO.dispatchEvent( evt.clone() );
132
if( !captureContProp )
133
evt.stopPropagation();