• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 879
  • Last Modified:

Detect mouse RollOver and RollOut with actionscript

So here is my problem I have built a movie with some sliding buttons that react to MouseOver events.  But the problem is that if you run your mouse over them quickly they stay all the way out instead of sliding back in.

Right now its all done with tweening and using Mouse events but is there a sure fire way to make sure that if that mouse leave the button it will slide in and if the mouse slides over it will slide out?

Thanks

LAter

IC
0
InnerChild
Asked:
InnerChild
  • 6
  • 4
  • 2
  • +1
1 Solution
 
hsmtpCommented:
Hi InnerChild,

use hitTest combining with onEnterFrame of some movieClip.
Read more in help about hitTest.
0
 
InnerChildAuthor Commented:
Would you have any examples that I could try?  I have found some tutorials online but they didn't seem to help.

Thanks

IC
0
 
hsmtpCommented:
InnerChild,

_root.createEmptyMovieClip("cycler", 12345);
_root.cycler.onEnterFrame = function() {
    if (_root.myButton.hitTest(_root._xmouse, _root._ymouse, true)) {
         // mouse inside the button
    } else {
         // mouse outside the button
    }
}
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
hsmtpCommented:
if you have only one frame in button, use can use it directly without cycler MC:


_root.myButton.onEnterFrame = function() {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
         // mouse inside the button
    } else {
         // mouse outside the button
    }
}

0
 
InnerChildAuthor Commented:
I tried the second AS and got this error message

**Error** Symbol=mona_roll, layer=Layer 2, frame=12:Line 1: Statement must appear within on handler
     _root.mona_roll.onEnterFrame = function() {

I then tried it in a on (rollOut) and the animation worked but the problem with the button is still there.

IC
0
 
InnerChildAuthor Commented:
Also tried the first AS, and tried both on the movie clip instead of the button......
Nothing working properly let.

IC
0
 
hsmtpCommented:
InnerChild,

What version of Flash do you use?
0
 
benlowryCommented:
Try this:

ButtonClip.onRollOver = function()
{
    this.onEnterFrame = function()
    {
         if(this._x < sometargetvalue)
         {
                 this._x += 1;
          }
          else
          {
                delete this.onEnterFrame;
          }
     }
}

Button.onRollOut = function()
{
    this.onEnterFrame = function()
    {
         if(this._x > sometargetvalue)
         {
                 this._x -= 1;
          }
          else
          {
                delete this.onEnterFrame;
          }
     }
}

What's happening here is we're creating an onEnterFrame function each time the mouse passes on or off a button.  When the onEnterFrame's if condition is satisfied the function is deleted.  If a user mouses off a button while the on function is still occuring, the onEnterFrame will simply change to the new one.

Hope this makes sense,
Ben
0
 
SavongCommented:
If that doesn't help you may want to try simply changing the frames per second option for the stage, if it is at the default of 12 it can cause something like what you've described (no guarantees though).
0
 
InnerChildAuthor Commented:
Sorry about the late reply this is one of a few projects I am working on....

benlowry
Hate to sound like such a newbie but where am I putting this code?  (mona_roll) is the buttons instance name)

Also Savong the frame rate is at 16 so that probably isn't the problem.

Thanks

IC
0
 
benlowryCommented:
on the keyframe where the buttons are stored.
-----------------------------------------------------------------------------------------------
mona_roll.onRollOver = function()
{
    this.onEnterFrame = function()
    {
         if(this._x < sometargetvalue)
         {
                 this._x += 1;
          }
          else
          {
                delete this.onEnterFrame;
          }
     }
}

mona_roll.onRollOut = function()
{
    this.onEnterFrame = function()
    {
         if(this._x > sometargetvalue)
         {
                 this._x -= 1;
          }
          else
          {
                delete this.onEnterFrame;
          }
     }
}


or
-----------------------------------------------------------------------------------------------
if they're Button clips, on the buttons themselves:

on(rollOver)
{
    this.onEnterFrame = function()
    {
         if(this._x < sometargetvalue)
         {
                 this._x += 1;
          }
          else
          {
                delete this.onEnterFrame;
          }
     }
}

on(rollOut)
{
    this.onEnterFrame = function()
    {
         if(this._x > sometargetvalue)
         {
                 this._x -= 1;
          }
          else
          {
                delete this.onEnterFrame;
          }
     }
}

or
-----------------------------------------------------------------------------------------------
if they're movieclips, on the movieclips themselves:
mona_roll.onLoad = function()
{
    this.onRollOver = function()
    {
        this.onEnterFrame = function()
        {
             if(this._x < sometargetvalue)
             {
                    this._x += 1;
              }
            else
             {
                delete this.onEnterFrame;
             }
        }
    }

    this.onRollOut = function()
    {
        this.onEnterFrame = function()
        {
             if(this._x > sometargetvalue)
            {
                 this._x -= 1;
             }
             else
             {
                delete this.onEnterFrame;
             }
        }
    }
}

Any of these 3 options should do you fine.  Pick whichever you're most comfortable with.  I prefer having my code in keyframes on the _root timeline.  You might prefer them on clips.
0
 
InnerChildAuthor Commented:
Hey benlowry

This may be a little late now and I don't know if you will get this but I thought it was fixed but it turns out is isn't.  I was trying to use the movieclips AS you gave me but I am getting this error....

**Error** Scene=Scene 1, layer=slide menu, frame=1:Line 1: Statement must appear within on/onClipEvent handler
     tails_roll.onLoad = function()

Total ActionScript Errors: 1        Reported Errors: 1

I know it said mona in your AS but I changed it for a different button....

0
 
InnerChildAuthor Commented:
Man this always happens after I post......I got the button AS working just the way I need it so I don't need any extra hand holding.

Thanks for everything

IC
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now