我正在尝试在 Adobe Animate 2015 中像http://www.flashuser.net/eyes-following-mouse-cursor-as3这样的光标来关注
function getMousePos(canvasDom, mouseEvent) {
var rect = canvasDom.getBoundingClientRect();
return {
x: mouseEvent.clientX - rect.left,
y: mouseEvent.clientY - rect.top
};
}
canvas.addEventListener("mousemove", function (e) {
mousePos = getMousePos(this, e);
var xx = mousePos.x - this.Reye.x;
var yy = mousePos.y - this.Reye.y;
var radiusR1 = Math.atan2(yy, xx);
var degreeR1 = radiusR1 / (Math.PI / 180);
this.Reye.rotation = degreeR1;
}, false);
但我在浏览器中有错误
TypeError: Cannot read property 'x' of undefined
这段代码工作正常
this.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler(evt)
{
var xx = stage.mouseX - this.Reye.x;
var yy = stage.mouseY - this.Reye.y;
var radiusR1 = Math.atan2(yy, xx);
var degreeR1 = radiusR1 / (Math.PI / 180);
this.Reye.rotation = degreeR1;
}