9 Replies Latest reply on Aug 18, 2010 7:07 AM by kglad

    On Rollover Action

    scalhoun11

      I'm creating a quiz where a user picks up some text and drops it into a box (simple drag n drop scenario). The problem is when a user rolls over the answer box with the text I need some actions to execute but they won't. The usual on(rollover) commands don't work because the mouse is pressed down since the user is dragging text. Any way around this?

       

      I tried a my_mc.onEnterFrame command with a hitTest which works but then it loops repeatedly. I then deleted onEnterframe, which works the first time but then is deleted, so when I need to drop a second answer into that same answer box doesn't do anything. This didn't seem like the most elegant solution anyway. (Actually, just so I would know, is there a way to reinstate or restore a deleted onEnterFrame command?)

       

      commands for answer text:

       

      on (press) {
          this.startDrag();
      }

       

      on (release, releaseOutside) {
          if (this._droptarget == "/answer1")
          {// answer is right
              trace("right answer")
          }
          else
          {// answer is wrong
            trace("wrong")
          }
          this.stopDrag();
      }

       

      commands for answer box:

       

      on(rollOver) {

           trace("answer box")

      }

        • 1. Re: On Rollover Action
          kglad Adobe Community Professional & MVP

          you can use a loop and hitTest to see if the mouse is over a hotspot when dragging an object that interferes with mouse events.

          • 2. Re: On Rollover Action
            scalhoun11 Level 1

            Do you mean using a while loop? Or for? Could you post a little sample code? Thanks.

            • 3. Re: On Rollover Action
              kglad Adobe Community Professional & MVP

              no, you could use an enterframe loop or setinterval loop or mousemove loop.  i see you used an enterframe loop but had some trouble.  show the enterframe loop you were using.

              • 4. Re: On Rollover Action
                scalhoun11 Level 1

                my_mc.onEnterFrame = function()

                 

                {

                 

                    if (my_mc.hitTest(_xmouse, _ymouse, true))

                 

                    {

                 

                        trace("test");

                 

                        delete this.onEnterFrame;

                 

                    }

                 

                };

                 

                This works the first time and the word "test" is traced. The problem then is I need to it to work additional times but it's been deleted. And if I removed the delete it just traces test repeatedly which I don't want either.

                • 5. Re: On Rollover Action
                  kglad Adobe Community Professional & MVP

                  when do you want that trace("test") to execute?  when you rollover my_mc while something's being dragged?  if yes, does it matter what's being dragged?

                  • 6. Re: On Rollover Action
                    scalhoun11 Level 1

                    Yea, so the full code would be:

                     

                    This is correct answer text:

                     

                    on (press) {
                        this.startDrag();
                    }

                     

                    on (release) {
                        if (this._droptarget == "/answer1_mc")
                        {// answer is right
                            trace("right answer")
                        }
                        else
                        {// answer is wrong
                          trace("wrong")
                        }
                        this.stopDrag();
                    }

                     

                     

                     

                    This is the correct answer box:

                     

                    answer1_mc.onEnterFrame = function()

                     

                    {

                     

                        if (answer1.hitTest(_xmouse, _ymouse, true))

                     

                        {

                     

                            trace("test");

                     

                            delete this.onEnterFrame;

                     

                        }

                     

                    };

                     

                    So when a user picks up the first answer box and rolls over answer1_mc then a trace or something should happen. Currently nothing happens until the answer is released.

                    • 7. Re: On Rollover Action
                      kglad Adobe Community Professional & MVP

                      use:

                       

                      answer1_box.onPress=function(){
                      this.startDrag();
                      this.onMouseMove=function(){
                      if(answer1.hitTest(_xmouse,_ymouse)){
                      trace('test");
                      delete this.onMouseMove;
                      }
                      }
                      }

                       

                      answer1_box.onRelease=function() {

                          if (this._droptarget == "/answer1_mc")
                          {// answer is right
                              trace("right answer")
                          }
                          else
                          {// answer is wrong
                            trace("wrong")
                          }
                          this.stopDrag();
                      }

                      • 8. Re: On Rollover Action
                        scalhoun11 Level 1

                        Wonderful. Thanks. Sorry for the confusing naming. I wasn't as concerned about names and such just trying to find the right bit of code. Thanks kglad.

                        • 9. Re: On Rollover Action
                          kglad Adobe Community Professional & MVP

                          you're welcome.