3 Replies Latest reply on Sep 15, 2015 6:57 AM by Tony Heagren

    Attach MC / drag / release

    Tony Heagren Level 1

      Hi all,

       

      I'm building a point and click game with an inventory system and it's going pretty well.

      Hit a snag which I can't seem to solve.

       

      I want a user to be able to click on an MC (i.e. press and release the mouse), the MC

      attaches to the mouse, the user takes the MC to another MC and on click a conditional collision

      test occurs.

       

      Real world -

      1) User clicks on the Zippo MC to pick it up, takes it over to the candle MC and clicks the wick,

      the Zippo MC disappears (and the candle lights) - I can do the lighting...

       

      2) User clicks on the Zippo MC to pick it up, takes it over to the wine bottle, clicks it and

      nothing happens because they have no relationship.

       

      All and any help much appreciated.

       

      Best wishes

      Tony

       

       

      PS - I had surgery recently and while I'm recovering I thought I'd avoid TV, dust off an old skill (Flash) and build a game.

      Please bear with me if I ask a lot of ten year old questions - it's been a while since I played with this and I'm on some pretty

      heavy medication ! 

        • 1. Re: Attach MC / drag / release
          Tony Heagren Level 1

          I got the first part working like this:

           

          declare a global variable in frame one:

          _global.clicked =1;

           

          then put this code on an MC:

           

          onClipEvent (mouseDown) {

            homeX = 124.5;

            homeY = 275.5;

            if (_global.clicked==2) {

            stopDrag();

            setProperty(this, _x, homeX);

            setProperty(this, _y, homeY);

            } else {

            startDrag(this);

            _global.clicked = 2;

            _root.timer.play();

            }

          }

           

          This works - once - but how can I have it work again and again?

           

          Is anybody out there???  : )

          • 2. Re: Attach MC / drag / release
            Tony Heagren Level 1

            Solved it like this:

             

            onClipEvent (mouseDown) {

              homeX = 124.5;

              homeY = 275.5;

              if (XYZ==2) {

              stopDrag();

              setProperty(this, _x, homeX);

              setProperty(this, _y, homeY);

              XYZ = 1;

              } else {

              startDrag(this);

              XYZ = 2;

              }

            }

             

            Now to sort out the conditional hit test...

            • 3. Re: Attach MC / drag / release
              Tony Heagren Level 1

              Loving this conversation with myself...

               

              Case solved - if someone could make it more elegant I'd be grateful  : )

               

              on (release) {

                if (XYZ==2) {

                stopDrag();

                XYZ = 1;

                } else {

                startDrag(this);

                }

              }

              on (release) {

                if (_root.thing, hitTest(_root.ground)) {

                //do stuff

                setProperty(this, _visible, 0);

                } else if (_root.thing, hitTest(_root.red_herring)) {

                // do other stuff

                }

              }