Skip to main content
Participating Frequently
October 17, 2022
Question

Converting Actionscript code to HTML5

  • October 17, 2022
  • 1 reply
  • 119 views

This is my code, I am getting no errors but the eye are not moving.

var root = this;
var container, var1, var2, var3, radius1, radius2, eyeR, eyeL;
var shapes = [];

function main()
{
root.stop();
container = root.container;
eyeR = root.eyeR;
eyeL = root.eyeL;
container.mouseChildren = false;
eyeR.mouseChildren = false;
eyeL.mouseChildren = false;
stage.enableMouseOver(20);
container.on("mouseMove", mouseMoved);
}

 

function mouseMoved(e)
{
var1 = e.stageY - 270 / stage.scaleY;
var2 = e.stageX - 380 / stage.scaleX;
var3 = e.stageX - 580 / stage.scaleX;
radius1 = Math.atan2(var1,var2);
radius2 = Math.atan2(var1, var3);
eyeR.setTransform(580,270,1,1,radius2);
eyeL.setTransform(380,270,1,1,radius1);
}

 

main();

 

 

This is how I made it work in P5.js and ActionScript for refernce on how it should work.

https://editor.p5js.org/JWNimble/sketches/4-cBgdHkH

 ActionScript Code

stage.addEventListener("mouseMove", arjun);
function arjun(e:MouseEvent):void
{
var var1 = mouseY - eyeR.y;
var var2 = mouseX - eyeR.x;
var radiusR = Math.atan2(var1,var2);
var degreeR = radiusR / (Math.PI / 180);
eyeR.rotation = degreeR;

var var3 = mouseY - eyeL.y;
var var4 = mouseX - eyeL.x;
var radiusR1 = Math.atan2(var3,var4);
var degreeR1 = radiusR1 / (Math.PI / 180);
eyeL.rotation = degreeR1;
}

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    October 17, 2022