A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: How do I snap objects on my drag-n-drop puzzle?

  1. #1
    Junior Member
    Join Date
    Mar 2001
    Posts
    15
    I made a puzzle that works great. Only, I cannot find any resources on how to make the objects snap in my movie. This is hopefully a simple oversight in the actionscript code but I cannnot find the answer. Any help is greatly appreciated.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Posts
    263
    j.gilbert,

    Nothing left out of the code that would be needed for
    snapping puzzle parts into place.

    Since I can't see your code, this logic has the puzzle parts
    being dropped onto objects that will have the same x,y and rotation
    properties as the puzzle parts.

    When you drop the puzzel part, have the script check to see if
    the part has dropped onto the proper object and also check if it
    is within set limits to the x,y cords. and if it is then set the
    x,y and rotation property of the dropped piece to the drop target
    x,y and rotation.

    Hope this helps.
    MA

  3. #3
    Junior Member
    Join Date
    Mar 2001
    Posts
    15
    MA,

    Thanks for your reply. Sorry about leaving out the code. On my MC I have:

    on (press) {
    startDrag ("");
    }
    on (release) {
    stopDrag ();
    }


    That's all I have for the MC. It works fine with drag and drop, I guess I just need to get the x,y concept down. Will you tell me where to input x,y code or do you know of a tutorial of the top of your head I can go to?

    Thanks again for your reply.

  4. #4
    Junior Member
    Join Date
    Mar 2001
    Posts
    14
    There is a great book that I have Macromedia Flash Advanced that clearly explains this kind of thing. The author is Russell Chunn Check out the info around page 192 This will answer your questions. The book is the Visual QuickPro Series.

    Hope this helps you even more!!

  5. #5
    Junior Member
    Join Date
    Mar 2001
    Posts
    15
    Brightrd,

    Thanks for the direction. I'll get the book!


  6. #6
    Senior Member
    Join Date
    Sep 2000
    Location
    POA, Brazil
    Posts
    323
    I'm with a problem that's very close to yours, I even posted a thread too.....

    But I think (think, think) I have the solution for your problem. If I understood it, y want your MC to be dragged, then, once they are in the right place, they can´t be moved anymore, right?
    I made a MC, with a button in the 1° frame, and a static graphic in the 2°, at the same location n equal to the button. 1° frame =

    Stop
    Set Variable: "OrigemX" = GetProperty ("",_x)
    Set Variable: "OrigemY" = GetProperty ("",_y)

    2° frame is = Stop

    Then at the button, the folowing code

    On (Press)
    Start Drag (GetProperty(_x, _y))
    // stores the x n y coordinates values
    End On
    On (Release)
    Stop Drag
    If (_droptarget eq "/olhos")
    // name of the target area, a MC with a graphic with one frame, positioned at the scene, no actions.
    Go to Next Frame
    // then the MC goes to that frame wich has the graphic, remenber, placed at the same spot.
    Else
    Set Property ("", Y Position) = OrigemY
    Set Property ("", X Position) = OrigemX
    // if the MC wasn´t dropped at the correct target area, it goes back to the place it was before
    End If
    End On


    Hope I've helped y.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center