03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

someListener.onMouseDown = function () { ... };<br />

Mouse.addListener(someListener);<br />

Listeners enable different pieces of code to cooperate because multiple listeners can receive<br />

notification about a single event.<br />

A Flash application can only monitor mouse events that occur within its focus. A Flash<br />

application cannot detect mouse events in another application.<br />

Availability: <strong>ActionScript</strong> 1.0; Flash Player 6<br />

Example<br />

The following example uses the Drawing API to draw a rectangle whenever the user clicks,<br />

drags <strong>and</strong> releases the mouse at runtime.<br />

this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth());<br />

var mouseListener:Object = new Object();<br />

mouseListener.onMouseDown = function() {<br />

this.isDrawing = true;<br />

this.orig_x = _xmouse;<br />

this.orig_y = _ymouse;<br />

this.target_mc = canvas_mc.createEmptyMovieClip("",<br />

canvas_mc.getNextHighestDepth());<br />

};<br />

mouseListener.onMouseMove = function() {<br />

if (this.isDrawing) {<br />

this.target_mc.clear();<br />

this.target_mc.lineStyle(1, 0xFF0000, 100);<br />

this.target_mc.moveTo(this.orig_x, this.orig_y);<br />

this.target_mc.lineTo(_xmouse, this.orig_y);<br />

this.target_mc.lineTo(_xmouse, _ymouse);<br />

this.target_mc.lineTo(this.orig_x, _ymouse);<br />

this.target_mc.lineTo(this.orig_x, this.orig_y);<br />

}<br />

updateAfterEvent();<br />

};<br />

mouseListener.onMouseUp = function() {<br />

this.isDrawing = false;<br />

};<br />

Mouse.addListener(mouseListener);<br />

The MovieClip.getNextHighestDepth() method used in this example requires Flash Player<br />

7 or later. If your SWF file includes a version 2 component, use the version 2 components'<br />

DepthManager class instead of the MovieClip.getNextHighestDepth() method.<br />

See also<br />

addListener (Mouse.addListener method)<br />

820 <strong>ActionScript</strong> classes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!