Animate CC get mouse x y coordinates
How do I return the x and y stage pixel coordinates in Animate CC?
How do I return the x and y stage pixel coordinates in Animate CC?
The 'this' in the function is not the current timeline. Either add a .bind(this) to mouseMoved:
this.addEventListener("mousemove", mouseMoved.bind(this));
or use another variable:
var self = this;
function mouseMoved(e) {
self.my_movieclip.x = e.pageX;
};
If you look in the Code Snippets panel, under HTML5 Canvas, there's an example that shows how to do a custom cursor, which is on the same lines as what you're trying to do.
Thanks Colin for steering me to the code snippets. Here is the working code (Gets mouse position and causes movieClip to follow mouse without hiding the cursor):
this.addEventListener("tick", fl_CustomMouseCursor.bind(this));
function fl_CustomMouseCursor() {
this.ball.x = stage.mouseX;
this.ball.y = stage.mouseY;
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.