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

ActionScript function (move object with cursor)

Community Beginner ,
Jun 22, 2019 Jun 22, 2019

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

620
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

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*_

...
Translate
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*_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;

}

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

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;

});

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

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