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

ActionScript function (move object with cursor)

Community Beginner ,
Jun 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

I have created a piece of code, based on code from this tutorial

Design simple interactive content |

which makes the object turn at 180 degree following the cusor movements.

I like to ask if anybody can tell me what code I should use, if I would like the object to follow the cursor around the stage ?

I have the following code in ActionScript 3,

stage.on('stagemousemove', function(e){

var radians = Math.atan2(e.localY - _this.test.y, e.localX - _this.test.x);

var degrees = radians * (180 / Math.PI);

_this.test.rotation = degrees - 180;

});

Also if anybody could tell me where to find ActionScript code in general and if possible examples of ActionScript code and functions.

Thanks

Views

425

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

correct answers 1 Correct answer

Community Expert , Jun 22, 2019 Jun 22, 2019

that's not as3.  it looks like createjs and you're missing the definition for _this.

it's also not clear what you want.  if you want _this.test to 'tween' to the cursor use something like:

var _this=this;

var speed = .95; // 0 to 1

var fI;

stage.on('stagemousemove', function(e){

var radians = Math.atan2(e.localY - _this.test.y, e.localX - _this.test.x);

var degrees = radians * (180 / Math.PI);

_this.test.rotation = degrees - 180;

_this.test.x = speed*_this.test.x+(1-speed)*e.localX;

_this.test.y = speed*_

...

Votes

Translate

Translate
Community Expert ,
Jun 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

that's not as3.  it looks like createjs and you're missing the definition for _this.

it's also not clear what you want.  if you want _this.test to 'tween' to the cursor use something like:

var _this=this;

var speed = .95; // 0 to 1

var fI;

stage.on('stagemousemove', function(e){

var radians = Math.atan2(e.localY - _this.test.y, e.localX - _this.test.x);

var degrees = radians * (180 / Math.PI);

_this.test.rotation = degrees - 180;

_this.test.x = speed*_this.test.x+(1-speed)*e.localX;

_this.test.y = speed*_this.test.y+(1-speed)*e.localY;

clearInterval(fI);

fI=setInterval(f.bind(e),50);

});

function f(){

_this.test.x = speed*_this.test.x+(1-speed)*this.localX;

_this.test.y = speed*_this.test.y+(1-speed)*this.localY;

}

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 Beginner ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

Thanks, and yes you are right, it is createjs 🙂

Here is the complete code for the rotation of an object, posted in my my question, if anybody like to try it out.

stage.enableMouseOver(30);

var _this = this;

stage.on('stagemousemove', function(e){

var radians = Math.atan2(e.localY - _this.test.y, e.localX - _this.test.x);

var degrees = radians * (180 / Math.PI);

_this.test.rotation = degrees - 90;

});

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 ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

LATEST

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