Link to home
Start Free TrialLog in
Avatar of InnerChild
InnerChild

asked on

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
Avatar of hsmtp
hsmtp

Hi InnerChild,

use hitTest combining with onEnterFrame of some movieClip.
Read more in help about hitTest.
Avatar of InnerChild

ASKER

Would you have any examples that I could try?  I have found some tutorials online but they didn't seem to help.

Thanks

IC
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
    }
}
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
    }
}

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
Also tried the first AS, and tried both on the movie clip instead of the button......
Nothing working properly let.

IC
InnerChild,

What version of Flash do you use?
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
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).
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
ASKER CERTIFIED SOLUTION
Avatar of benlowry
benlowry

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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....

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