03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - 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.

onMouseDown (Mouse.onMouseDown event<br />

listener)<br />

onMouseDown = function() {}<br />

Notified when the mouse button is pressed. To use the onMouseDown listener, you must create<br />

a listener object. You can then define a function for onMouseDown <strong>and</strong> use addListener() to<br />

register the listener with the Mouse object, as shown in the following code:<br />

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

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 />

Note: This event listener is supported in Flash Lite only if System.capabilities.hasMouse<br />

is true or System.capabilities.hasStylus is true.<br />

Example<br />

The following example uses the Drawing API to draw a rectangle when the user presses the<br />

mouse button, moves the mouse, <strong>and</strong> then releases the mouse button 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 />

396 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!