9 Replies Latest reply on Aug 28, 2006 7:48 AM by kglad

    If / then statements - please help!

    Boghog
      Hello!

      I'm trying to program a movie clip object so that it plays Frame 1 when the cursor hovers over it, Frame 2 when it's clicked on, and Frame 3 when it's dragged away. BUT, I want it to remain on Frame 4 constantly after it's been dragged. At the moment, it's going back to Frame 1 when the cursor hovers over it, etc - as you would expect. What I need is some kind of if/then statement, like this:

      if (object) has been dragged then ignore all previous code for this object

      Unfortunately I'm not proficient enough with ActionScript to know exactly what form this statement should take. Could someone point me in the right direction please?

      Thanks!
        • 1. Re: If / then statements - please help!
          Level 7
          Boghog,

          > I'm trying to program a movie clip object so that it plays
          > Frame 1 when the cursor hovers over it, Frame 2 when
          > it's clicked on, and Frame 3 when it's dragged away.

          Okay.

          > BUT, I want it to remain on Frame 4 constantly after it's
          > been dragged. At the moment, it's going back to Frame 1
          > when the cursor hovers over it, etc - as you would expect.

          I would only expect that if the event handlers for those events were
          still engaged. How have you programmed the existing handlers? Are you
          using on() or onClipEvent()?

          > What I need is some kind of if/then statement, like this:
          >
          > if (object) has been dragged then ignore all
          > previous code for this object

          Nah, you don't need an if() statement. All you need is to write a
          function that turns off the other event handlers after the dragging is
          complete. Let's see your existing code, and I'll help you with your goal.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: If / then statements - please help!
            2m Level 2
            you would better add a property (aka variable) to your clip, let's say we call it hasBeenDragged this variable is initiylly set to false:

            myClip_mc.hasBeenDragged = false;

            in you "onDrag" function you would use sonething like that:

            myClip_mc.onPress = function(){
            this.startDrag();
            this.hasBeenDragged = true();
            }

            Your rollOut statment would look someting like that:

            myClip_mc.onRollOut = myClip.onReleaseOutside = function (){
            if (this.hasBeenDargged){
            this.gotoAndStop(1);
            }
            else {
            this.gotoAndStop(4);
            }
            }

            This is the concept, ther might be typos in the code as I didn't test it.
            • 3. Re: If / then statements - please help!
              Boghog Level 1
              This is what I've got so far:


              on (press) {startDrag(this);

              }
              on (release) {stopDrag();

              }
              on (rollOver) {gotoAndPlay(2);

              }
              on (rollOut) {gotoAndPlay(1);

              }
              on (press) {gotoAndPlay(3);

              }
              on (dragOut) {gotoAndPlay(4);

              }
              on (dragOut) {bagdragged = "true";
              }
              on (release) {

              if (bagdragged == "true") {
              gotoAndStop(4);
              }
              }
              • 4. Re: If / then statements - please help!
                2m Level 2
                Hi,

                due to the time it takes for newsgroup messages I didn't see Davids reply when I wrote my first reply (btw. "Hi David"):

                Which way to go, the one David suggested or the on I pointed you depends on whether you want the clip to be reactive to rollovers after it has been draged of not. But with one of the describet techniques you should be able to solve you problem, or with a combination of both.
                • 5. Re: If / then statements - please help!
                  Level 7
                  > (btw. "Hi David"):

                  Hi, 2m. :)

                  > Which way to go, the one David suggested or the on I
                  > pointed you depends on whether you want the clip to
                  > be reactive to rollovers after it has been draged of not.

                  Given that Boghog's sample code uses on(), an if() statement may just be
                  the way to go, after all. on() is Flash 5 era code, for what it's worth.
                  It still works and is perfectly "legal," but such event handlers behave
                  differently from the more modern approach (see details here ...
                  http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent).

                  In the case of on(), you've said you only want the rollOver
                  gotoAndPlay() to occur if dragging hasn't already occurred. You're using a
                  variable to record this "toggle," so after bagdragged equals "true," you
                  merely have to check the value of that variable. In fact, you're already
                  doing this in your release handler.

                  on (rollOver) {
                  (if bagdragged == "true") {
                  gotoAndPlay(2);
                  }
                  }


                  David Stiller
                  Adobe Community Expert
                  Dev blog, http://www.quip.net/blog/
                  "Luck is the residue of good design."


                  • 6. Re: If / then statements - please help!
                    Boghog Level 1
                    Thanks for the help - I think I'm getting closer to a solution, but now I'm having another problem. This is the code I have now:

                    on (press) {startDrag(this);}
                    on (release) {stopDrag();}
                    on (rollOver) {gotoAndPlay(2);}
                    on (press) {gotoAndPlay(3);}
                    on (startDrag) {gotoAndPlay(4);}
                    on (startDrag) {bagdragged = true;}
                    on (rollOver) {if (bagdragged = true) {gotoAndPlay(4);}}
                    on (press) {if (bagdragged = true) {gotoAndPlay(4);}}

                    For some reason that I can't fathom at all, when the cursor hovers over the object it goes straight to Frame 4 and stays there. I've looked closely at the above code and I can't work out why it would do this. Can anyone shed some light?

                    Thanks!
                    • 7. Re: If / then statements - please help!
                      kglad Adobe Community Professional & MVP
                      use the double equal (==) to test for equality. otherwise, flash interprets your single equal as the assignment operator and is assigning bagdragged to be true and then going to frame 4.
                      • 8. Re: If / then statements - please help!
                        Boghog Level 1
                        Thanks for the help. I think I'm on top of it now.

                        Cheers!
                        • 9. Re: If / then statements - please help!
                          kglad Adobe Community Professional & MVP
                          you're welcome.