1 Reply Latest reply on Mar 31, 2008 6:36 PM by Lukewig

    Force-pickup a moveable sprite

    Level 7
      Is there a way to force the pickup of a moveable sprite via code? Let's
      explain the problem with a little diagram here, (pardon my horrible ASCII
      art, which is probably font-width-dependant). I've got a small icon (A)
      inside a larger rectangle (B), like so:
      | ____ |
      | |_A_ | B |

      Now, icon (A) is a moveable sprite, and can be dragged into a certain
      location elsewhere on the stage. (B) is a box with a bit of descriptive
      text regarding icon (A). (There are actually 4 sprites involved, but (A) is
      the only one that moves.) What I want to do is make it so that clicking
      anywhere within box (B) will cause the icon (A) to jump into your mouseLoc
      and then be draggable, just as if you'd clicked directly onto (A). Now,
      I've put script onto the box (B) like so:

      on mouseDown me
      sprite(A).loc = the mouseLoc

      This indeed causes the sprite to jump under the mouseLoc, but it won't
      drag - you have to click again in order to pick it up. I tried adding a
      "sprite(A).mouseDown()" to trick it into believing there was an actual mouse
      event, but this had no effect. (This technique DOES activate any script
      MouseDown events on sprite (A), but it doesn't cause it to be draggable.)
      The "pass" command doesn't seem to be doing anything here either. (In fact,
      I've almost never gotten that thing to work properly - it really doesn't
      seem to do what the docs say it does.) Is there some way to cheat the
      computer into thinking you clicked on the sprite when you really didn't?

        • 1. Re: Force-pickup a moveable sprite
          Lukewig Level 1

          I don't think you can pass the 'click to start drag'. Its pretty easy to do it in lingo though.

          -- Behaviour on the clickable sprite (B)

          on mouseDown me
          targetSprite = A
          tmp = script("FollowMouse").new(targetSprite)

          -- Parent Script "FollowMouse"
          property mySprite

          on new (me, whatSpriteToChase)
          mySprite = sprite(whatSpriteToChase)
          mySprite.loc = the mouseLoc

          on enterframe (me)
          if the mouseDown then
          mySprite.loc = the mouseLoc
          end if