Link to home
Start Free TrialLog in
Avatar of jasonbb
jasonbbFlag for Australia

asked on

FLASH - Snap moving hand onto keys of a music keyboard

I'm using "startDrag" to initiate a dragging of my movieclip which is the graphic of a hand.

This works but I want to snap the hand over the keys so the finger is over the middle of the key it's over - not smoothly drag over the keyboard.

Is this possible?
With Thanks.
Avatar of quizengine
quizengine
Flag of United Kingdom of Great Britain and Northern Ireland image

If you issue 'startDrag' the hand will *always* follow the mouse.

Do you want it to either

a) follow the mouse but 'snap' to the closest one when the mouse is released ?

or

b) with the mouse down,not move at all until the next 'key' is reached and then 'snap'

Both of these require a different approach.

If you are able to share the fla that should make it easier. Plus, what version of actionscript, and what version of Flash are you using ?
Avatar of jasonbb

ASKER

Thanks QuizEngine,
AS3 version 9. I want option B. I tried the following code to test:
      private function mouseMoveHandler(event:MouseEvent):void
      {
            mcHand.x = mcHand.x & 0xffffffc0;
      }
It worked in that the hand snapped but it also skipped around horizontally as i moved the mouse and looked really bad.
I'm really sorry, Jasonbb - I'm stuck in the past.  I may be a 'master' but only of AS2. Good luck finding someone who uses AS3 to crack your issue.
to answer the original question, yes you can - you'd set up a mouseMove handler that compared the current mouse position to the positions of each key element, and compute the distance.  For the key that's closest to the mouse position, you'd set the hand cursor element to that key element's position.

but, it sounds like you don't want to drag it at all - but rather just position it over the key when the key is mouseovered.  this would be very simple - instead of a drag, just set a mouseOver event handler to each key that sets the hand cursor element's position to the position of the event.currentTarget.

i've attached a snippet with examples for both approaches.  open a new FLA and paste the contents in the frame 1's action's panel and run Test Movie to see the demo.  the first (un-commented) bit is using the mousemove approach; the second (commented) bit is using the mouseOver of individual elements aproach.  Just comment out or uncomment the one you want to try.
ASKER CERTIFIED SOLUTION
Avatar of moagrius
moagrius
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jasonbb

ASKER

thanks moagrius that's unreal