Mouse position: Difference between revisions

Content added Content deleted
(ActionScript implementation)
Line 1: Line 1:
{{task|GUI}}[[Category:Testing]]Get the current location of the mouse cursor relative to the active window. Please specify if the window may be externally created.
{{task|GUI}}[[Category:Testing]]Get the current location of the mouse cursor relative to the active window. Please specify if the window may be externally created.

=={{header|ActionScript}}==
This shows the mouse position in a text field at the bottom-right corner and updates when the mouse is moved.
<lang ActionScript3>
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class MousePosition extends Sprite {
private var _textField:TextField = new TextField();
public function MousePosition() {
if ( stage ) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
_textField.autoSize = TextFieldAutoSize.RIGHT;
_textField.x = stage.stageWidth - 10;
_textField.defaultTextFormat = new TextFormat(null, 15);
_textField.text = "Mouse position: X = 0, Y = 0";
_textField.y = stage.stageHeight - _textField.textHeight - 14;
addChild(_textField);
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
private function _onEnterFrame(e:Event):void {
_textField.text = "Mouse position: X = " + stage.mouseX + ", Y = " + stage.mouseY;
}
}

}
</lang>

=={{header|Ada}}==
=={{header|Ada}}==
{{libheader|GTK|GtkAda}}
{{libheader|GTK|GtkAda}}