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

createJS - move obj along with mouse

Participant ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

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

Views

586

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;

});

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks you Joae .

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

No problem!

You're welcome!

Votes

Translate

Translate

Report

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