In ActionScript, mouse listeners can be installed to receive notifications about mouse movement, left mouse button press and mouse wheel events. In Flash these events are traditionally handled by using the Mouse.addListener method to install a listener object that implements the following methods:
After the listener object is installed, its appropriate methods will be called whenever their corresponding events occur. In Flash, the onMouseDown and onMouseUp methods will only be called for the LEFT mouse button, no public interface is provided for receiving other mouse button events.
To address this limitation (and for supporting multiple mouse cursors) Scaleform extends these method calls by allowing them to take extra arguments when _global.gfxExtensions variable is set to true. The new function signatures are as follows:
* onMouseDown = function(button : Number, [targetPath : String], [mouseIdx : Number], [x : Number], [y : Number], [dblClick : Boolean]) { } * onMouseUp = function(button : Number, [targetPath : String], [mouseIdx : Number], [x : Number], [y : Number]) { }
When the assigned listener function takes at least one extra argument, Scaleform will call that listener method for the RIGHT, MIDDLE and other mouse buttons as well, allowing your logic to detect those events. The value for LEFT is 1, RIGHT is 2 and MIDDLE is 3. Currently, up to 16 buttons are supported. For compatibility, if the function is declared to take no arguments, it will only be called for the LEFT mouse button, which is identical to Flash. Below is an example of how such handlers can be installed:
var mouseListener:Object = new Object; mouseListener.onMouseDown = function(button, target) { trace("mouseDown - button '" + button + "' target = '" + target + "'"); } mouseListener.onMouseUp = function(button, target) { trace("mouseUp - button '" + button + "' target = '" + target + "'"); } Mouse.addListener(mouseListener);
The new mouse down/up handlers take at least two arguments: button and target. The first argument, button, describes the mouse button that was pressed; you can interpret it by comparing button to the Mouse["LEFT"], Mouse["RIGHT"] and Mouse["MIDDLE"] extension constants (Mouse["LEFT"] syntax is used instead of Mouse.LEFT in order to quiet the ActionScript 2.0 compiler). The second argument, target, provides the path to the topmost object under the mouse cursor at the time mouse was pressed; it can be 'undefined' if no such path is available.
In Flash, all extra arguments will always be “undefined”, as the handlers are only called for the left mouse button. You can interpret the undefined value as the LEFT mouse button to ensure compatibility with the Flash player.
For supporting multiple mouse cursors, there are extra parameters for each handler:
* onMouseMove = function([mouseIdx : Number], [x : Number], [y : Number]) { } * onMouseDown = function(button : Number, [targetPath : String], [mouseIdx : Number], [x : Number], [y : Number], [dblClick : Boolean]) { } * onMouseUp = function(button : Number, [targetPath : String], [mouseIdx : Number], [x : Number], [y : Number]) { } * onMouseWheel = function(delta : Number, targetPath : String, [mouseIdx : Number], [x : Number], [y : Number]) { }
The parameter mouseIdx contains the zero-based index of the mouse cursor caused the event. The x and y parameters contain the coordinates of the mouse cursor (in _root coordinate space). The dblClick parameter of onMouseDown handler indicates if a double-click occurred. In this case this parameter will contain a true value.