Copy link to clipboard
Copied
I want it so everytime I hover over a specific object I can move it just left or right. I have attached a photo of the scene. Basically, I want it so when you hover your mouse over the knife you can move it left or right (not up or down).
Copy link to clipboard
Copied
If you move your mouse quickly, and get outside of the width of the knife, would it stop following the mouse?
You could make it just follow the mouse all the time, and not insist that the user has to initially point at the knife. You could have code like this ('knife' is the instance name you gave the knife movieclip in the Properties panel):
addEventListener(Event.ENTER_FRAME,moveknife);
function moveknife(e:MouseEvent){
knife.x = stage.mouseX;
}
If you want to make sure the mouse is within the knife, you could do this:
addEventListener(Event.ENTER_FRAME, moveknife);
function moveknife(e: Event) {
if (knife.hitTestPoint(stage.mouseX, stage.mouseY, true)) {
knife.x = stage.mouseX;
}
}
You'll see though that it's easy to move away from the knife and lose control of it.
Copy link to clipboard
Copied
The second one is perfect! Thank you so much!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now