I'm trying to make eye following for cursor like this http://www.flashuser.net/eyes-following-mouse-cursor-as3 in Adobe Animate 2015
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);
but i have error in browser
TypeError: Cannot read property 'x' of undefined
and this code is working fine
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;
}