Help with Javascript, dragging an object
So I Found a few example of what I want but I have questions.
Links I'm looking at:
https://www.createjs.com/tutorials/Mouse%20Interaction/
Now both of those look to offer what I want to do at the basic level.
I have some nested movieclips. A measurment guage face with a needle pointing, the needle is a separate symbol inside the face movie clip. When I move the face down I want to the needle to rotate.
So far I'm on the moving down part...
I only want to be able to click and drap on the y axis. so someone clicking and moving can only move the face up and down. I want to have a maximum and minimum dragability.
The second link has this code:
var root = this;
var rec = root.rec;
createjs.Touch.enable(stage);
rec.on("mousedown", function(e)
{
e.currentTarget.offsetX = stage.mouseX / stage.scaleX - e.currentTarget.x;
e.currentTarget.offsetY = stage.mouseY / stage.scaleY - e.currentTarget.y;
});
rec.on("pressmove", function(e)
{
e.currentTarget.x = stage.mouseX / stage.scaleX - e.currentTarget.offsetX;
e.currentTarget.y = stage.mouseY / stage.scaleY - e.currentTarget.offsetY;
});
I'm trying to understand the code here. why doesn't it just go var rec = this.rec;? instead of the two var lines at the top? And how to I get the ID of the object I want to move? I don't really know where to find the name of my object is it the instance name?
If I remove the lines with X will it just work on Y? How to I set a max up and a max down?
The first link has this code:
circle.on("pressmove", function(evt) {
evt.target.x = evt.stageX;
evt.target.y = evt.stageY;
});
circle.on("pressup", function(evt) { console.log("up"); })
This is considerably less text. But I have similar questions. how to get the name of my object I want to use. If I just remove the lines with X will it just work with Y? How to add a max height and minimum?
Also where do I put this code? on the main timeline or in the movie clip somewhere?
Then, Is it possible to use the distance dragged to control the rotation of a nested symbol?
I know that's a lot but I am pretty lost here and want to know how to get this to work. I'm new to code and haven't used animate since... Flash CS6.
