public static removeListener(listener:Object) : Boolean
Removes an object that was previously registered with addListener().
Note: This method is supported in Flash Lite only if System.capabilities.hasMouse is true or System.capabilities.hasStylus is true.
listener:Object - An object.
Boolean - If the listener object is successfully removed, the method returns true; if the listener object is not successfully removed (for example, if it was not on the Mouse object's listener list), the method returns false.
The following example attaches three buttons to the Stage, and lets the user draw lines in the SWF file at runtime, using the mouse pointer. One button clears all of the lines from the SWF file. The second button removes the mouse listener so the user cannot draw lines. The third button adds the mouse listener after it is removed, so the user can draw lines again. Add the following ActionScript to Frame 1 of the Timeline:
this.createClassObject(mx.controls.Button, "clear_button", this.getNextHighestDepth(), {_x:10, _y:10, label:'clear'});
this.createClassObject(mx.controls.Button, "stopDrawing_button", this.getNextHighestDepth(), {_x:120, _y:10, label:'stop drawing'});
this.createClassObject(mx.controls.Button, "startDrawing_button", this.getNextHighestDepth(), {_x:230, _y:10, label:'start drawing'});
startDrawing_button.enabled = false;
//
this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth());
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
this.isDrawing = true;
canvas_mc.lineStyle(2, 0xFF0000, 100);
canvas_mc.moveTo(_xmouse, _ymouse);
};
mouseListener.onMouseMove = function() {
if (this.isDrawing) {
canvas_mc.lineTo(_xmouse, _ymouse);
}
updateAfterEvent();
};
mouseListener.onMouseUp = function() {
this.isDrawing = false;
};
Mouse.addListener(mouseListener);
var clearListener:Object = new Object();
clearListener.click = function() {
canvas_mc.clear();
};
clear_button.addEventListener("click", clearListener);
//
var stopDrawingListener:Object = new Object();
stopDrawingListener.click = function(evt:Object) {
Mouse.removeListener(mouseListener);
evt.target.enabled = false;
startDrawing_button.enabled = true;
};
stopDrawing_button.addEventListener("click", stopDrawingListener);
var startDrawingListener:Object = new Object();
startDrawingListener.click = function(evt:Object) {
Mouse.addListener(mouseListener);
evt.target.enabled = false;
stopDrawing_button.enabled = true;
};
startDrawing_button.addEventListener("click", startDrawingListener);