Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

createJS - move obj along with mouse

Participant ,
Jan 18, 2018 Jan 18, 2018

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

TOPICS
ActionScript
648
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 18, 2018 Jan 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;

});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 28, 2018 Feb 28, 2018

Thanks you Joae .

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2018 Mar 01, 2018
LATEST

No problem!

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines