Highlighted

ActionScript function (move object with cursor)

Community Beginner ,
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

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

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;

}

Views

141

Likes

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

ActionScript function (move object with cursor)

Community Beginner ,
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

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

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;

}

Views

142

Likes

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
Jun 22, 2019 0
Adobe Community Professional ,
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;

}

Likes

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
Reply
Loading...
Jun 22, 2019 0
Community Beginner ,
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;

});

Likes

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
Reply
Loading...
Jun 23, 2019 0
kglad LATEST
Adobe Community Professional ,
Jun 23, 2019

Copy link to clipboard

Copied

you're welcome.

Likes

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
Reply
Loading...
Jun 23, 2019 0