Skip to main content
Inspiring
January 18, 2018
Question

createJS - move obj along with mouse

  • January 18, 2018
  • 2 replies
  • 697 views

Hi,

I'm new to createJS.

I tried an object to move along with mouse on stage. I have a movieclip with the instance name of "mc1" and have given the below code on the frame.

stage.addEventListener("stagemousemove", function(evt) {

this.mc1.x = evt.stageX;

this.mc1.y = evt.stageY;

});

Nothing happening in the browser when I move mouse on the stage. When I try to alert(this.mc1), it says "undefined"

Please help me how to make it works.

Thanks,

Guru

This topic has been closed for replies.

2 replies

RajaguruVAuthor
Inspiring
March 1, 2018

Thanks you Joae .

Sorry for my very late reply. I was in the other task.

JoãoCésar17023019
Community Expert
Community Expert
March 1, 2018

No problem!

You're welcome!

JoãoCésar17023019
Community Expert
Community Expert
January 18, 2018

Create a variable outside your function to store the correct scope.

var that = this;

stage.addEventListener("stagemousemove", function(evt) {

that.mc1.x = evt.stageX;

that.mc1.y = evt.stageY;

});