API Docs for: 最后更新日期:2014年8月25日
Google搜索   
Show:

File: display/LInteractiveObject.js

/** @language english
 * <p>The LInteractiveObject class is the abstract base class for all display objects with which the user can interact, using the mouse.</p>
 * @class LInteractiveObject
 * @extends LDisplayObject
 * @constructor
 * @since 1.9.0
 * @public
 */
var LInteractiveObject = (function() {
	function LInteractiveObject() {
		var s = this;
		LExtends(s, LDisplayObject, []);
		s.type = "LInteractiveObject";
		/** @language english
		 * Specifies whether this object receives mouse, or other user input, messages. The default value is true, which means that by default any InteractiveObject instance that is on the display list receives mouse events or other user input events. If mouseEnabled is set to false, the instance does not receive any mouse events (or other user input events like keyboard events). Any children of this instance on the display list are not affected. To change the mouseEnabled behavior for all children of an object on the display list, use LDisplayObjectContainer.mouseChildren.
		 * @property mouseEnabled
		 * @type Boolean
		 * @since 1.8.10
		 * @example
		 * 	LGlobal.setDebug(true);
		 * 	var button01 = new LButtonSample1("mouseEnabled=true");
		 * 	button01.x = button01.y = 20;
		 * 	addChild(button01);
		 * 	button01.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
		 * 		trace("button01 click");
		 * 	});
		 * 	var button02 = new LButtonSample1("mouseEnabled=false");
		 * 	button02.x = 20;
		 * 	button02.y = 150;
		 * 	button02.mouseEnabled = false;
		 * 	addChild(button02);
		 * 	button02.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
		 * 		trace("button02 click");
		 * 	});
		 * @examplelink <p><a href="../../../api/LInteractiveObject/mouseEnabled.html" target="_blank">Try it »</a></p>
		 * @public
		 */
		s.mouseEnabled = true;
		s.mouseList = new Array();
	}
	var p = {
		addEventListener : function(type, listener) {
			var s = this;
			if (type.indexOf("mouse") >= 0 || type.indexOf("touch") >= 0 || type == LMouseEvent.DOUBLE_CLICK) {
				if (LMouseEventContainer.container[type] || ((type == LMouseEvent.MOUSE_OVER || type == LMouseEvent.MOUSE_OUT) && LMouseEventContainer.container[LMouseEvent.MOUSE_MOVE])) {
					LMouseEventContainer.addMouseEvent(s, type, listener);
					return;
				}
				s.mouseList.push({
					listener : listener,
					type : type
				});
			} else {
				s._eventList.push({
					listener : listener,
					type : type
				});
			}
		},
		removeEventListener : function(type, listener) {
			var s = this, i, length;
			if (type.indexOf("mouse") >= 0 || type.indexOf("touch") >= 0 || type == LMouseEvent.DOUBLE_CLICK) {
				if (LMouseEventContainer.container[type] || ((type == LMouseEvent.MOUSE_OVER || type == LMouseEvent.MOUSE_OUT) && LMouseEventContainer.container[LMouseEvent.MOUSE_MOVE])) {
					LMouseEventContainer.removeMouseEvent(s, type, listener);
					return;
				}
				length = s.mouseList.length;
				for ( i = 0; i < length; i++) {
					if (!s.mouseList[i]) {
						continue;
					}
					if (type == s.mouseList[i].type && s.mouseList[i].listener == listener) {
						s.mouseList.splice(i, 1);
						return;
					}
				}
			} else {
				return s.callParent("removeEventListener", arguments);
			}
		},
		removeAllEventListener : function() {
			var s = this;
			s.mouseList.length = 0;
			s._eventList.length = 0;
			if (LMouseEventContainer.container[LMouseEvent.MOUSE_DOWN]) {
				LMouseEventContainer.removeMouseEvent(s, LMouseEvent.MOUSE_DOWN);
			}
			if (LMouseEventContainer.container[LMouseEvent.MOUSE_UP]) {
				LMouseEventContainer.removeMouseEvent(s, LMouseEvent.MOUSE_UP);
			}
			if (LMouseEventContainer.container[LMouseEvent.MOUSE_MOVE]) {
				LMouseEventContainer.removeMouseEvent(s, LMouseEvent.MOUSE_MOVE);
				LMouseEventContainer.removeMouseEvent(s, LMouseEvent.MOUSE_OVER);
				LMouseEventContainer.removeMouseEvent(s, LMouseEvent.MOUSE_OUT);
			}
		},
		hasEventListener : function(type) {
			var s = this, i, length;
			if (type.indexOf("mouse") >= 0 || type.indexOf("touch") >= 0 || type == LMouseEvent.DOUBLE_CLICK) {
				length = s.mouseList.length;
				for ( i = 0; i < length; i++) {
					if (!s.mouseList[i]) {
						continue;
					}
					if (type == s.mouseList[i].type) {
						return true;
					}
				}
			} else {
				return s.callParent("hasEventListener", arguments);
			}
			return false;
		}
	};
	for (var k in p) {
		LInteractiveObject.prototype[k] = p[k];
	}
	return LInteractiveObject;
})(); 
/** @language english
 * Dispatched when a user presses the pointing device button over an LInteractiveObject instance.
 * <p><a href="LMouseEvent.html#property_MOUSE_DOWN">LMouseEvent.MOUSE_DOWN</a></p>
 * @event LMouseEvent.MOUSE_DOWN
 */
/** @language english
 * Dispatched when a user releases the pointing device button over an LInteractiveObject instance.
 * <p><a href="LMouseEvent.html#property_MOUSE_UP">LMouseEvent.MOUSE_UP</a></p>
 * @event LMouseEvent.MOUSE_UP
 */
/** @language english
 * Dispatched when a user moves the pointing device while it is over an LInteractiveObject.
 * <p><a href="LMouseEvent.html#property_MOUSE_MOVE">LMouseEvent.MOUSE_MOVE</a></p>
 * @event LMouseEvent.MOUSE_MOVE
 */
/** @language english
 * Dispatched when the user moves a pointing device away from an LInteractiveObject instance.
 * <p><a href="LMouseEvent.html#property_MOUSE_OUT">LMouseEvent.MOUSE_OUT</a></p>
 * @event LMouseEvent.MOUSE_OUT
 */
/** @language english
 * Dispatched when the user moves a pointing device over an LInteractiveObject instance.
 * <p><a href="LMouseEvent.html#property_MOUSE_OVER">LMouseEvent.MOUSE_OVER</a></p>
 * @event LMouseEvent.MOUSE_OVER
 */
/** @language english
 * Dispatched when a user presses and releases the main button of a pointing device twice in rapid succession over the same LInteractiveObject.
 * <p><a href="LMouseEvent.html#property_DOUBLE_CLICK">LMouseEvent.DOUBLE_CLICK</a></p>
 * @event LMouseEvent.DOUBLE_CLICK
 */