核心改进文件1
(function(){/**
* 全局开始时间点
*
* @static
* @property _globalStartTimer
* @type {Number}
* @private
* @module buildingBlock
*/
_globalStartTimer = (new Date()).getTime();
/**
* (全局函数)返回从进入界面开始到现在的时间间隔。
* @static
* @class getTimer
* @return {int}
* @module buildingBlock
*/
getTimer = function(){
_currentTimer = (new Date()).getTime();
return parseInt(_globalStartTimer - _currentTimer);
}
})();
/**
* 执行继承。
* 旧代码会导致一个错误,就是子类在继承并执行基类构造函数时,基类构造函数中的 this,
* 为当前子类的对象引用,而此时子类还并未具备父类的方法,所以,基类中用 this 调用其方法是显示提示:
* "ReferenceError: (methodName) is not defined"。
* @static
* @class base
* @module buildingBlock
* @param {Object} thisObj
* @param {Object} baseClass
* @param {Array} argArr
*/
function base(thisObj, baseClass, argArr) {
var p=null,o=thisObj.constructor.prototype,h={};
for(p in o)h=1;
for(p in baseClass.prototype){
if(!h)o = baseClass.prototype;
o = baseClass.prototype;
}
if(Object.prototype.callParent){
delete Object.prototype.callParent;
}
/* try{*/
baseClass.apply(thisObj,argArr);
/* }catch(err){
trace(this + ".base(...) argArr = " + argArr + "--> 错误名称:" + err.name + ", \n错误信息:" + err.message );
}*/
} /**
* 此类在 core.js 中进行扩展,扩展自 lufylegend-1.7.7 : LPoint 类
* @class LPoint
*/
/**
* [静态] 返回 pt1 和 pt2 之间的距离。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
*
* @static
* @method distance
* @param {LPoint} pt1
* @param {LPoint} pt2
* @return {Number}
*/
LPoint.distance = function (pt1, pt2){
return LPoint.distance2(pt1.x, pt1.y, pt2.x, pt2.y);
};
/**
* [静态] 返回点 x1,y1 和点 x2,y2 之间的距离。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
*
* @method distance2
* @param {Number} x1 第一点的 x 轴。
* @param {Number} y1 第一点的 y 轴。
* @param {Number} x2 第二点的 x 轴
* @param {Number} y2 第二点的 y 轴。
* @return {Number}
*/
LPoint.distance2 = function(x1, y1, x2, y2){
//最佳方法为。
var x = x1 - x2;
var y = y1 - y2;
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
};
/**
* [静态] 确定两个指定点之间的点。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
*
* @static
* @method interpolate
* @param {LPoint} pt1 第一个点。
* @param {LPoint} pt2 第二个点。
* @param {Number} f 两个点之间的内插级别。表示新点将位于 pt1 和 pt2 连成的直线上的什么位置。
* 如果 f=1,则返回 pt1;如果 f=0,则返回 pt2。
* @return {LPoint}
*/
LPoint.interpolate = function(pt1, pt2, f){
var _x = pt2.x - pt1.x;
var _y = pt2.y - pt1.y;
var tanVal = _y / _x;
var radians = Math.atan(tanVal);//获得角弧度。
var sinVal = Math.sin(radians);
var length = _y / sinVal;
length *= f;
var newY = length * sinVal;
var newX = newY / tanVal;
return new LPoint(newX, newY);
};
/**
* [静态] 将一对极坐标转换为笛卡尔点坐标。* 未实现 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @static
* @method polar
* @param {Number} len 极坐标对的长度。
* @param {Number} angle 极坐标对的角度(以弧度表示)。
* @return {LPoint}
*/
LPoint.polar = function (len, angle){
return new LPoint(0,0);
};
/**
* 按指定量偏移 Point 对象。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method offset
* @param {Number} dx
* @param {Number} dy
* @return {void}
*/
LPoint.prototype.offset = function(dx, dy){
this.x += dx;
this.y += dy;
};
/**
* 将 Point 的成员设置为指定值。 * 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method setTo
* @param {Number} xa
* @param {Number} ya
* @return {void}
*/
LPoint.prototype.setTo = function(xa, ya){
this.x = xa;
this.y = ya;
};
/**
* 从 (0,0) 到此点的线段长度。
* @method getLength
* @return {Number}
*/
LPoint.prototype.getLength = function(){
return LPoint.distance(LPoint.EMPTY, this);
};
/**
* 创建此 LPoint 对象的副本。
* @method clone
* @return {LPoint}
*/
LPoint.prototype.clone = function(){
return new LPoint(this.x, this.y);
};
/**
* 将另一个点的坐标添加到此点的坐标以创建一个新点。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method add
* @param {LPoint} v
* @return {LPoint}
*/
LPoint.prototype.add = function(v){
return new LPoint(this.x + v.x, this.y + v.y);
};
/**
* 从此点的坐标中减去另一个点的坐标以创建一个新点。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method subtract
* @param {LPoint} v
* @return {LPoint}
*/
LPoint.prototype.subtract = function(v){
return new LPoint(this.x - v.x, this.y - v.y);
};
/**
* 确定两个点是否相同。* 扩展 lufylegend-1.7.7 LPoint 类。 *
* @method equals
* @param {LPoint} toCompare
* @return Boolean
*/
LPoint.prototype.equals = function(toCompare){
return (this.x == toCompare.x && this.y == toCompare.y);
};
/**
* 将源 LPoint 对象中的所有点数据复制到调用方 LPoint 对象中。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method copyFrom
* @param {LPoint} sourcePoint
* @return {void}
*/
LPoint.prototype.copyFrom = function(sourcePoint){
this.setTo(sourcePoint.x, sourcePoint.y);
};
/**
* 将 (0,0) 和当前点之间的线段缩放为设定的长度。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method normalize
* @param {Number} thickness 缩放值。例如,如果当前点为 (0,5) 并且您将它规范化为 1,则返回的点位于 (0,1) 处。
* @return {void}
*/
LPoint.prototype.normalize = function (thickness){
var pt1 = LPoint.EMPTY;
var _x = this.x - pt1.x;
var _y = this.y - pt1.y;
var tanVal = _y / _x;
var radians = Math.atan(tanVal);//获得角弧度。
var sinVal = Math.sin(radians);
this.y = thickness * sinVal;
this.x = this.y / tanVal;
};
/**
* 一个全局静态的点,值为 x = 0, y = 0。注意: 请不要更改此对象的属性。 * 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @static
* @property EMPTY
* @type {LPoint}
*/
LPoint.EMPTY = new LPoint(0,0); /**
* 全局对象累的,此类在。
* @class LGlobal
*/
/**
* LGlobal.mouseEvent
*
* @static
* @method mouseEvent
* @param {LMouseEvent} e 鼠标事件。
* @param {String} t 事件类型。
*/
LGlobal.mouseEvent = function(e, t) {
//console.log("core.js -> LGlobal.mouseEvent(e, t) e.type = " + e.type);
e.type = t;
var k = null;
for (k = LGlobal.childList.length - 1; k >= 0; k--) {
if (LGlobal.childList.mouseEvent) {
if(LGlobal.childList.mouseEvent(e, t)){
break;
}
}
}
};
/**
* lufylegend-1.8.1 类 LEventDispatcher
* @method LEventDispatcher
*/
/**
* LEventDispatcher.addEventListener(type, listener),添加一个事件侦听器。
* @method addEventListener
* @param {String} type 事件类型
* @param {Function|Delegate} listener 事件侦听器,一个事件处理函数或者一个事件委托。
*/
//LEventDispatcher.prototype.addEventListener=function(type,listener){
// this._eventList.push({listener:listener,type:type});
//};
/**
* 【重写函数】LEventDispatcher.removeEventListener(type,listener)
* @method removeEventListener
* @param {String} type 事件类型。
* @param {Function|Delegate} 事件侦听器,一个事件处理函数或者一个事件委托。
*/
LEventDispatcher.prototype.removeEventListener=function(type,listener){
var s = this,i,length;
this._removeEventListener(type, s._eventList, listener);
};
/**
* @method
*
*/
/**
* 使用本方法来删除指定事件类型的事件。
* @method _removeEventListener
* @param {String} type 事件类型。
* @param {Array} eventList 事件侦听记录表。
* @param {Function|Delegate} listener 事件侦听器类型为:Function or Delegate
* @private
*/
LEventDispatcher.prototype._removeEventListener = function(type, eventList, listener) {
length = eventList.length;
var item;
for(i=0;i<length;i++){
item = eventList;
if(type == item.type && item.listener == listener){
eventList.splice(i,1);
return ;
}else if(type == item.type &&
listener instanceof Delegate &&
item.listener instanceof Delegate &&
item.listener.isEqual(listener)
){
item.listener.dispose();
listener.dispose();
eventList.splice(i,1);
return ;
}
}
};
/**
* LEventDispatcher.removeAllEventListener() 移除对象所有侦听。
* @method removeAllEventListener
*/
//LEventDispatcher.prototype.removeAllEventListener=function (){
// this._eventList = [];
//};
/**
* 【重写函数】 LEventDispatcher.dispatchEvent(eventType|eventObject)
* @method dispatchEvent
* @param {String|BEvent} type 本参数可以是一个String类型的 eventType,也可以是一个 eventObject 的引用。
*/
LEventDispatcher.prototype.dispatchEvent=function(type){
//console.log("lufylegend-1.8.1.js dispatchEvent(type) type = " + type);
var s = this;
var i,length = s._eventList.length;
var listener;
var event;
var o;
//组件原始方法。
if(typeof type === "string"){
//console.log("core-lufylegend-1.8.1.js dispatchEvent(type) type = " + type);
for(i=0;i<length;i++){
if(type == s._eventList.type){
s.target = s;
s.event_type = type;
//s._eventList.listener(s);
o = s._eventList;
//console.log("core-lufylegend-1.8.1.js dispatchEvent(type) o.listener instanceof Function = " + (o.listener instanceof Function));
if(o.listener instanceof Function){
/* try{*/
o.listener.apply(this, );
/* }catch(err){
trace(this + ".dispatchEvent(type) = "+ + " -->错误名称:" + err.name + ", \n错误信息:" + err.message);
}*/
}else if(o.listener instanceof Delegate){
o.listener.run();
}
//return;
}
}
}else {
//使用抛出事件
event = type;
if(typeof event.type === "string"){
for(i=0;i<length;i++){
if(event.type == s._eventList.type){
event.currentTarget = s;
o = s._eventList;
//console.log("core-lufylegend-1.8.1.js dispatchEvent(type) o.listener instanceof Function = " + (o.listener instanceof Function));
if(o.listener instanceof Function){
o.listener.apply(this, );
}else if(o.listener instanceof Delegate){
o.listener.run();
}
//return;
}
}
}
}
};
/**
* LEventDispatcher.hasEventListener(type) 检查是否添加了指定类型的事件侦听。
* @method hasEventListener
* @param {String} type
* @returns {boolean}
*/
//LEventDispatcher.prototype.hasEventListener=function(type){
// var s = this,i,length = s._eventList.length;
// for(i=0;i<length;i++){
// if(type == s._eventList.type)return true;
// }
// return false;
//};
//输出窗口提示。
{
console.log("注意:现使用 core.js 重写的 LSprite.mouseEvent(e, type, cd) 函数!");
}
/**
* @class LDisplayObject
* @returns {LPoint}
*/
/**
* @method getRootCoordinate
* @returns {LPoint}
*/
LDisplayObject.prototype.getRootCoordinate = function(){
var s = this;
var sx=s.x,sy=s.y;
var p = s.parent;
while(p != "root"){
sx *= p.scaleX;
sy *= p.scaleY;
sx += p.x;
sy += p.y;
p = p.parent;
}
return new LPoint(sx,sy);
}; LDisplayObject.prototype.getRootBounds = function (){
var s = this;
var sx = s.x,
sy = s.y,
sw = s.getWidth(),
sh = s.getHeight();
var p = s.parent;
while(p != "root" && typeof p !== UNDEFINED){
sx *= p.scaleX;
sy *= p.scaleY;
sw *= p.scaleX;
sh *= p.scaleY;
sx += p.x;
sy += p.y;
p = p.parent;
}
return new LRectangle(sx, sy, sw, sh);
};
/**
* @class LInteractiveObject
*/
/**
* [重写函数] LInteractiveObject.addEventListener()
* @method addEventListener
* @param {String} type
* @param {Function|Delegate} listener
*/
LInteractiveObject.prototype.addEventListener = function(type,listener){
//console.log("addEventListener(...) type = " + type);
Assert.isString(type, "LInteractiveObject.js addEventListener(...) type must be String!" + type);
Assert.isNotNull(listener, "LInteractiveObject.js addEventListener(...) listener cannot be null!!");
var s = this;
if(type == LEvent.ENTER_FRAME){
s.frameList.push(listener);
}else if(type.indexOf("mouse")>=0 || type.indexOf("touch")>=0){
s.mouseList.push({listener:listener,type:type});
}else{
this._eventList.push({listener:listener,type:type});
}
};
/**
* [重写函数]LInteractiveObject.removeEventListener(...)
* @method removeEventListener
* @param {String} type
* @param {Function|Delegate} listener
*/
LInteractiveObject.prototype.removeEventListener = function(type,listener){
var s = this,i,length;
if(type == LEvent.ENTER_FRAME){
length = s.frameList.length;
for(i=0;i<length;i++){
if(type == LEvent.ENTER_FRAME && s.frameList == listener){
s.frameList.splice(i,1);
return;
}
}
}else if(type.indexOf("mouse")>=0 || type.indexOf("touch")>=0){
this._removeEventListener(type, s.mouseList, listener);
}else{
this._removeEventListener(type, s._eventList, listener);
}
};
/**
* @class LGraphics
*/
/**
* 重写的 LGraphics.show
* @method show
*/
LGraphics.prototype.show = function (){
var s = this,k=null;
if(s.setList.length == 0)return;
//console.log("core-lufylegend-1.8.1.js -> LGraphics.show() setList.length = " + s.setList.length);
for(var k = 0, len = s.setList.length; k < len; k++){
//console.log(s.setList);
s.setList();
}
};
/**
* [重写函数] LGraphics.drawArc
* @method drawArc
* @param tn
* @param lco
* @param pa
* @param isf
* @param co
*/
LGraphics.prototype.drawArc = function(tn,lco,pa,isf,co){
var s = this,c;
s.setList.push(function(){
c=LGlobal.canvas;
c.beginPath();
c.arc(pa,pa,pa,pa,pa,pa);
if(s.bitmap){
c.save();
c.clip();
c.drawImage(s.bitmap.image,
s.bitmap.x,s.bitmap.y,s.bitmap.width,s.bitmap.height,
0,0,s.bitmap.width,s.bitmap.height);
c.restore();
s.bitmap=null;
return;
}
if(isf){
if(lco!="#ffffff"){
c.fillStyle = co;
c.fill();
}
}
if(tn>0){
c.lineWidth = tn;
c.strokeStyle = lco;
c.stroke();
}
});
s.showList.push({type:"arc",value:pa});
}; /**
* [重写函数]
* @method drawRect
* @param tn
* @param lco
* @param pa
* @param isf
* @param co
*/
LGraphics.prototype.drawRect = function (tn,lco,pa,isf,co){
// console.log("LGraphics.drawRect(" + tn + ", " + lco + ", " + pa + ", "+ isf + ", " + co + ")");
// console.log("LGraphics.drawRect(...) this = " + this);
var s = this,c;
s.setList.push(function(){
c=LGlobal.canvas;
c.beginPath();
c.rect(pa,pa,pa,pa);
c.closePath();
if(s.bitmap){
c.save();
c.clip();
// console.log("LGraphics.drawRect(tn,lco,pa,isf,co) s.bitmap.x = "+ s.bitmap.x + ",s.bitmap.y = " + s.bitmap.y);
c.drawImage(s.bitmap.image,
s.bitmap.x, s.bitmap.y, //0,0, /* 此处进行了修改。*、
s.bitmap.width,s.bitmap.height,
0,0,
s.bitmap.width,s.bitmap.height);
c.restore();
s.bitmap=null;
return;
}
if(isf){
if(lco!="#ffffff"){
c.fillStyle = co;
c.fill();
}
}
if(tn>0){
c.lineWidth = tn;
c.strokeStyle = lco;
c.stroke();
}
});
s.showList.push({type:"rect",value:pa});
};
/**
* [重写函数] 请检查本函数是否解注释,此函数必须解注释使用。* 在测试组件时,此函数将被注释。*
* @method ismouseon
* @param e
* @param co
* @returns {boolean}
*/
//LGraphics.prototype.ismouseon = function(e,co){
// var s = this;
// var k = null;
// if(e==null || e == UNDEFINED)return false;
// // 注意:LGlobal.minscale 属性原先的 lufylegend 组件中时没有的
// var minscale = typeof LGlobal.minscale === UNDEFINED ? 1 : LGlobal.minscale;
// if(co==null)co={x:0,y:0,scaleX:minscale,scaleY:minscale,alpha:1,rotate:0};
// var ox,oy;
// if(e.offsetX == UNDEFINED){
// ox = e.touches.pageX;
// oy = e.touches.pageY;
// }else{
// ox = e.offsetX;
// oy = e.offsetY;
// }
// for(k in s.showList){
// if(s.showList.type == "rect"){
// if(ox >= s.showList.value*minscale + co.x && ox <= s.showList.value*minscale + co.x + s.showList.value*minscale &&
// oy >= s.showList.value*minscale + co.y && oy <= s.showList.value*minscale + co.y + s.showList.value*minscale){
// return true;
// }
// }else if(s.showList.type == "arc"){
// var xl = s.showList.value*minscale + co.x - ox;
// var yl = s.showList.value*minscale + co.y - oy;
// return xl*xl+yl*yl <= s.showList.value*minscale*s.showList.value*minscale;
// }
// }
// return false;
//};
/**
* [重写函数] 鼠标感应重写。
* @method ismouseon
* @param e
* @param co
* @returns {boolean}
*/
LGraphics.prototype.ismouseon = function(e,co){
var s = this;
var k = null;
if(e==null || e == UNDEFINED)return false;
if(co==null)co={x:0,y:0,scaleX:1,scaleY:1,alpha:1,rotate:0};
var ox,oy;
if(e.offsetX == UNDEFINED){
ox = e.touches.pageX;
oy = e.touches.pageY;
}else{
ox = e.offsetX;
oy = e.offsetY;
}
for(k in s.showList){
if(s.showList.type == "rect"){
if(ox >= s.showList.value*co.scaleX + co.x && ox <= s.showList.value*co.scaleX + co.x + s.showList.value*co.scaleX &&
oy >= s.showList.value*co.scaleY + co.y && oy <= s.showList.value*co.scaleY + co.y + s.showList.value*co.scaleY){
// console.log("value = " + s.showList.value);
// console.log("e.offsetX = " + e.offsetX);
// console.log("e.offsetY = " + e.offsetY);
// console.log("LGraphics.ismouseon(...) left = " + (s.showList.value*co.scaleX + co.x ));
// console.log("LGraphics.ismouseon(...) right = " + (s.showList.value*co.scaleX + co.x + s.showList.value*co.scaleX));
// console.log("LGraphics.ismouseon(...) top = " + (s.showList.value*co.scaleY + co.y ));
// console.log("LGraphics.ismouseon(...) bottom = " + (s.showList.value*co.scaleY + co.y + s.showList.value*co.scaleY));
return true;
}
}else if(s.showList.type == "arc"){
var xl = s.showList.value*co.scaleX + co.x - ox;
var yl = s.showList.value*co.scaleY + co.y - oy;
return xl*xl+yl*yl <= s.showList.value*co.scaleX*s.showList.value*co.scaleX;
}
}
return false;
};
/**
*
* @class LBitmap
*/
/**
* 在已存在的父对象中删除自己。
* @method remove
*/
LBitmap.prototype.remove = function(){
var s = this;
if(!s.parent || s.parent == "root")return;
s.parent.removeChild(s);
};
/**
* [重写函数] LBitmap.ismouseon
* @method ismouseon
* @param e
* @param cood
* @returns {boolean}
*/
LBitmap.prototype.ismouseon = function(e,cood){
var s = this;
if(e==null || e == UNDEFINED)return false;
if(!s.visible || !s.bitmapData)return false;
if(cood==null)cood={x:0,y:0,scaleX:1,scaleY:1};
var ox,oy;
if(e.offsetX == UNDEFINED){
ox = e.touches.pageX;
oy = e.touches.pageY;
}else{
ox = e.offsetX;
oy = e.offsetY;
}
// console.log(this + "LBitmap.ismouseon(...) left = " + (s.x * cood.scaleX + cood.x));
// console.log("LBitmap.ismouseon(...) right = " + (s.x * cood.scaleX + cood.x + s.bitmapData.width*s.scaleX*cood.scaleX));
// console.log("LBitmap.ismouseon(...) top = " + (s.y * cood.scaleY + cood.y));
// console.log("LBitmap.ismouseon(...) bottom = " + (s.y * cood.scaleY + cood.y + s.bitmapData.height*s.scaleY*cood.scaleY));
//此处运算添加考虑父对象 y 轴缩放导致的 y 值实际变化。
if(ox >= s.x * cood.scaleX + cood.x && ox <= s.x * cood.scaleX + cood.x + s.bitmapData.width*s.scaleX*cood.scaleX &&
oy >= s.y * cood.scaleY + cood.y && oy <= s.y * cood.scaleY + cood.y + s.bitmapData.height*s.scaleY*cood.scaleY){
return true;
}else{
return false;
}
}; /**
* 此类用于使用 lufylegend 绘图应用程序编程接口 (API) 创建简单形状
* @class LShape
* @constructor
* @extends LSprite
*/
function LShape(){
base(this, LSprite, []);
this.type = "LShape";
this.toString = function (){
return "";
}
}
/**
*
* @class LSprite
*/
/**
* 检测是否是在遮罩范围内。
* @param {LMouseEvent} e 鼠标事件引用
* @param {Object} cd 包含当前抛出鼠标事件的对象基本信息的对象。{x: 0, y: 0, scaleX: 1, scaleY: 1, alpha: 1, rotate: 0};
* @return Boolean 当精灵没有遮罩或鼠标在遮罩范围内时返回true,否则返回false;
*/
LSprite.prototype.inMaskDomain = function(e, cd){
var s = this;
// console.log("LSprite.inMaskDomain(...) (s.mask instanceof LGraphics)" + (s.mask instanceof LGraphics));
// if(!(s.mask instanceof LGraphics)){
// return true;
// }
return s.mask.ismouseon(e, cd);
};
/**
* [重写函数] 原 LSprite.mouseEvent 检测鼠标事件是否发生在当前对象或其子对象上,若是则执行事件目标对象的鼠标事件处理器,
* 并终止鼠标事件继续传播,同时返回"true"。
* @method mouseEvent
* @param {LMouseEvent} e 鼠标事件对象
* @param {String} type 鼠标事件类型
* @param {Object} cd 包含当前抛出鼠标事件的对象基本信息的对象。{x: 0, y: 0, scaleX: 1, scaleY: 1, alpha: 1, rotate: 0};
* @returns {boolean}
*/
LSprite.prototype.mouseEvent = function (e,type,cd){
// console.log(this.name);
//console.log("core.js LSprite.mouseEvent(e, type, cd) -> e.type = " + e.type + ", type = " + type);
var returnBool = false; //返回是否有处理事件。
if(e==null || e == UNDEFINED)return false;
var s = this;
if(!s.mouseChildren || !s.visible)return false;
if(cd==null)cd={x:0,y:0,scaleX:1,scaleY:1};
var i,k,ox,oy;
if(e.offsetX == UNDEFINED){
ox = e.touches.pageX;
oy = e.touches.pageY;
}else{
ox = e.offsetX;
oy = e.offsetY;
}
// var mc = {x:s.x+cd.x,y:s.y+cd.y,scaleX:cd.scaleX*s.scaleX,scaleY:cd.scaleY*s.scaleY};
var mc = {x:s.x * cd.scaleX+cd.x,y:s.y * cd.scaleY+cd.y,scaleX:cd.scaleX*s.scaleX,scaleY:cd.scaleY*s.scaleY};
//检查是否在遮罩区域内。
if(s.mask && !s.inMaskDomain(e, cd)){
// if(type != LMouseEvent.MOUSE_MOVE){
// console.log("LSprite.mouseEvent(e,type, cd) s.mask.name = " + s.mask.name);
// console.log("LSprite.mouseEvent(e,type, cd) false = " + false);
// }
return false;
}
for(k=s.childList.length-1;k>=0;k--){
if(s.childList.mouseEvent){
i = s.childList.mouseEvent(e,type,mc);
/*
* 注意:
* lufylegend-1.7.7.js 中此处语句为 "if (i) return true;",即鼠标事件在遇到处理函数时,执行函数,而后就
* 不再向同级精灵与父级精灵传递事件。
* 在此让事件不再向同级别的底层精灵传递。但是继续向其上级传递。
*/
if (i){
returnBool = true;
//console.log("core.js LSprite.mouseEvent(e, type, cd) -> e.type = " + e.type);
//console.log("core.js LSprite.mouseEvent(e, type, cd) -> " + returnBool);
break;
}
}
}
/*
* 此处修改为图层无论是否添加鼠标侦听,都将使上层的鼠标事件不再传导到下层显示对象上。
* 即当作为最顶层中的最底层时,无论其有无侦听鼠标事件,只要鼠标在其上面点击,即事件直接上父级传播不再,向同级传播。
*/
// if(s.mouseList.length == 0) {
// return returnBool;
// }
if (returnBool && s.mouseList.length == 0) {
return returnBool;
}
// 检测鼠标事件是否发生在当前对象上,若是则执行其鼠标事件处理器。(未知是否会导致性能出现问题。)
var i = s.ismouseon(e, cd);
if(i){
// if(type != LMouseEvent.MOUSE_MOVE){
// console.log(this + ".mouseEvent(...) e.type = " + e.type + ", name = " + this.name + ", parent = " + this.parent);
// }
for(k=0;k<s.mouseList.length;k++){
var o = s.mouseList;
if(o.type == type){
/*e.type = type;*/ //此属性决定在 LGlobal.mouseEvent(...)里添加。
e.selfX = ox - (s.x+cd.x);
e.selfY = oy - (s.y+cd.y);
e.clickTarget = s;
if(o.listener instanceof Function){
/* try{*/
o.listener.apply(s, );
/* }catch(err){
LGlobal.output(this+ ".mouseEvent(... ) = " + + " --> 错误名称:" + err.name + ", \n错误信息:" + err.message );
}*/
}else if(o.listener instanceof Delegate){
o.listener.run();
}
//此处改为在代理的情况下使用代理。
// o.listener(e,s);
// 修改注释原语句是为了执行完所有的鼠标侦听。
// return true;
}
}
/*
* 注意:
* 此处原先语句为"return false",结果导致,下层显示对象在上层有遮挡时,依旧能够感应到鼠标事件。
*/
return true;
}else{
return returnBool;
}
};
LSprite.prototype.ismouseon = function(e,cd){
var s = this;
if(!s.visible || e==null)return false;
var k = null,i=false,l=s.childList;
// var sc={x:s.x+cd.x,y:s.y+cd.y,scaleX:cd.scaleX*s.scaleX,scaleY:cd.scaleY*s.scaleY,alpha:cd.alpha*s.alpha};
var sc={x:s.x * cd.scaleX+cd.x,y:s.y * cd.scaleY+cd.y,scaleX:cd.scaleX*s.scaleX,scaleY:cd.scaleY*s.scaleY,alpha:cd.alpha*s.alpha};
//当存在遮罩层的状态下,我们将将遮罩层做为鼠标事件的唯一感应区域,并判断遮罩层是否被鼠标单击到,并直接返回结果。
if(s.mask)
{ return s.mask.ismouseon(e, cd); }
//在没有遮罩层的状态下,将所有存在的子对象作为鼠标事件的感应区域。
for(k=l.length-1;k>=0;k--){
if(l.ismouseon)i = l.ismouseon(e,sc);
if(i)break;
}
if(!i && s.graphics)i = s.graphics.ismouseon(e,sc);
return i;
};
LSprite.prototype.setChildIndex = function(child/*:DisplayObject*/, index/*:int*/){
if(index < 0 || index >= s.childList.length){
return;
}
var s = this;
var i = s.childList.indexOf(child);
if(i == -1){
throw new Error(this + ".setChildIndex(child,index) 参数 child: " + child + " 不存在显示列表中!");
}
var arr = s.childList.splice(i,1);
s.childList.splice(index, 0, arr);
};
LSprite.prototype.swapChildren = function(child1/*:DisplayObject*/, child2/*:DisplayObject*/)/*:void*/{
var s = this;
var index1 = s.childList.indexOf(child1);
var index2 = s.childList.indexOf(child2);
if(index1 == -1){
throw new Error(this + ".swapChildren(child1, child2) 参数 child1:" + child1 + " 不存在显示列表中!");
}else if(index2 == -1){
throw new Error(this + ".swapChildren(child1, child2) 参数 child2:" + child2 + " 不存在显示列表中!");
}
s.childList = child1;
s.childList = child2;
};
LSprite.prototype.swapChildrenAt = function(index1/*:int*/, index2/*:int*/)/*:void*/ {
var s = this;
if(index1 < 0 || index1 >= s.childList.length){
throw new Error(this + ".swapChildrenAt(index1, index2) 参数 index1:" + index1 + " 索引值超出合法范围!");
}else if(index2 < 0 || index2 >= s.childList.length){
throw new Error(this + ".swapChildrenAt(index1, index2) 参数 index2:" + index2 + " 索引值超出合法范围!");
}
var child1 = s.childList;
var child2 = s.childList;
s.childList = child2;
s.childList = child1;
};
/**
* 文本字段类。
* @class LTextField
*/
/**
* 【重写函数】 LTextField.mouseEvent(event,type,cood)
* @method mouseEvent
* @param {LMouseEvent} event
* @param {String} type
* @param {Object} cood
* @returns {*}
*/
LTextField.prototype.mouseEvent = function (event,type,cood){
if(cood==null)cood={x:0, y:0, scaleX:1, scaleY:1};
var s = this;
if(s.inputBackLayer == null)return;
return s.inputBackLayer.mouseEvent(event,type,{x:s.x * cood.scaleX+cood.x, y:s.y*cood.scaleY+cood.y, scaleX:s.scaleX*cood.scaleX,scaleY: s.scaleY * cood.scaleY, alpha:1,rotate:0});
};
LSprite.prototype.toString = function (){
return "";
}; /**
* 全局函数,表示让指定类拥有函数集合。
* @class use
* @module buildingBlock
* @static
* @param classDef 类引用。
* @param {Object} methods 一个格式为 {methodName : function(){}, ...} 的对象
*/
function use(classDef, methods){
for (var name in methods)
{ classDef.prototype = methods; }
}
/**
* 在一个专门绘制背景图片的画布上绘制一个背景图。 * 此方法需要 LGlobal.bgCanvas 。*
* @method drawBackground
* @param bitmapData
*/
LGlobal.drawBackground = function(bitmapData){
LGlobal.canvas.clearRect(0, 0, LGlobal.width, LGlobal.height);
//LGlobal.canvas.fillRect(0,0,LGlobal.width,LGlobal.height);
var s=this;
LGlobal.bgCanvas.drawImage(bitmapData.image,
bitmapData.x,bitmapData.y,
bitmapData.width,bitmapData.height,
bitmapData.x,bitmapData.y,
bitmapData.width,bitmapData.height);
};
/**
* Created with JetBrains WebStorm.
* User: 陈前帆。
* Date: 13-10-10
* Time: 上午10:08
* To change this template use File | Settings | File Templates.
*/
/**
* 委托对象。允许您将事件委托给特定的范围和函数。
* @class Delegate
*/
/**
* 委托对象。允许您将事件委托给特定的范围和函数。
* @class Delegate
* @module buildingBlock
* @submodule utils
* @param {Object} $scopeObject 对对象的引用。这是运行函数的范围。
* @param {Function} $function 对函数的引用。
* @constructor
*/
function Delegate($scopeObject, $function){
if(typeof $scopeObject === "undefined"){
throw new Error("Delegate($scopeObject, $function) -> 参数 $scopeObject 不能为 " + $scopeObject + "!");
}else if(typeof $function === "undefined"){
throw new Error("Delegate($scopeObject, $function) -> 参数 $function 不能为 " + $function + "!");
}
/**
* 对对象的引用。这是运行函数的范围。
* @property scopeObject
* @type {Object}
*/
this.scopeObject = $scopeObject;
/**
* 对函数的引用。
* @property func
* @type {Function}
*/
this.func = $function;
}
/**
* 运行这个代理。
* @method run
* @param {Array} argArray 函数执行时的参数列表。
*/
Delegate.prototype.run = function (argArray){
if(typeof argArray === "undefined"){
argArray = [];
}
try{
this.func.apply(this.scopeObject, argArray);
}catch(err){
trace(this+ ".run(argArray) = " + argArray +" --> 错误信息:" + err.name + ", \n错误信息:" + err.message );
}
};
/**
* 破坏对象并回收内存。
* @method dispose
*/
Delegate.prototype.dispose = function (){
this.scopeObject = null;
this.func = null;
}
/**
* 当前代理是否与参数提供的代理一致。
* @static
* @method isEqual
* @param delegate
*/
Delegate.prototype.isEqual = function(delegate){
return this.scopeObject === delegate.scopeObject && this.func === delegate.func;
}
/**
* 创建一个函数
* method create
* @param {Object} $scopeObject 对对象的引用。这是运行函数的范围。
* @param {Function} $function 对函数的引用。
* @return {Delegate}
*/
Delegate.create = function($scopeObject, $function){
return new Delegate($scopeObject, $function);
} 此核心修改由原作者的代码进行一些修改。
1、添加显示对象缩放功能
2、缩放后鼠标感应位置的问题。
3、添加遮罩后鼠标感应范围在遮罩范围内。
4、添加 this 代理(Delegate),使得事件侦听器内this为代理所指定的 this 此模拟 actionScript 2.0 代码
5、添加上层遮挡下层鼠标事件。
6、增加事件实际冒泡,即事件在一个层的最底层接收并处理事件后,事件继续往上层冒泡,但是,不再向同层次对象传递。 根据你的组件我也写了一整套 模仿 Flex.spark 的组件。
但是,:'(最后,我发现添加显示对象的缩放功能是错误的决定,在显示器中,显示对象一但进行缩放,45 帧的频率能降到 19 :( 还有一个同事添加的就是当绘制的线的颜色为设置为 "ffffff" 时相当于绘制一个透明的区域(用于遮罩)