PDA

View Full Version : Flash Buttons on Rollout


Matthew Torneo
08-29-2005, 05:47 PM
I have created Flash buttons that when rolled over animate and reveal 2 or 3 choices for links. The buttons are movies with buttons inside of them. Everything is working properly but when you roll off the button very quickly, it does not animate back to it's original state. Thank you in advance for the help. This is the code I used:

onClipEvent (enterFrame) {
// if the mouse IS over the menu ...
if (this.hitTest (_root._xmouse, _root._ymouse, true))
{
// if the menu is NOT fully open
if (this._currentframe < this._totalframes)
{
// go to the next frame of the menu opening sequence
nextFrame ();
}
// if the mouse is NOT over the menu
}
else
{
// if the menu is NOT fully closed
if (this._currentframe > 1)
{
// play the previous frame of the menu opening sequence
prevFrame ();
}
}
}

Scottae
08-29-2005, 07:02 PM
Try something different. Delete the onClipEvent from your clip. Have no code on the clip itself. Then on the timeline where your clip exists, paste this code:

// Initially have clip stop
my_mc.stop ();

// Set the button events for your clip
my_mc.onRollOver = my_mc.onDragOver = onClipOver;
my_mc.onRollOut = my_mc.onDragOut = my_mc.onReleaseOutside = onClipOut;

// Method called on roll over of the clip
function onClipOver ():Void
{
this.onEnterFrame = animateOver;
}

// Method called on roll out of the clip
function onClipOut ():Void
{
this.onEnterFrame = animateOut;
}

// Method called by the enterframe event to animate the clip over
function animateOver ():Void
{
if (this._currentframe < this._totalframes)
this.nextFrame ();
else
delete this.onEnterFrame;
}

// Method called by the enterframe event to animate the clip out
function animateOut ():Void
{
if (this._currentframe > 1)
this.prevFrame ();
else
delete this.onEnterFrame;
}


Be sure to give your clip and instance name of my_mc....or you can just change the AS so my_mc is your clip's instance name.

:)

Matthew Torneo
08-29-2005, 07:19 PM
Thanks so much for the help, I am still very new to this and if you don't mind can you look at the document because I want to make sure you know exactly what I am referring to.

Thank you in advance

Scottae
08-29-2005, 08:14 PM
Ah yes.......buttons inside of the clips. That does screw things up a bit. Try this instead. Stick this code on that last keyframe on the main timeline....where your stop action is. Delete all the onClipEvent code on your buttons:

stop();

// Set the onEnterFrame event
onEnterFrame = checkOut;

// Create array and stick reference to buttons in the array
var buttons_array = new Array ();
buttons_array.push (applybutton);
buttons_array.push (mapbutton);
buttons_array.push (existingbutton);
buttons_array.push (brokerbutton);
buttons_array.push (referralbutton);
buttons_array.push (realestatebutton);

// Method called by the mouse move event to see if mouse is over clip
function checkOut ():Void
{
for (var i = 0; i < buttons_array.length; i++)
{
// Get reference to the button
var button_mc = buttons_array[i];

// If mouse is over the clip.....animate over......otherwise animate out
if (button_mc.hitTest (_xmouse, _ymouse, true))
button_mc.onEnterFrame = animateOver;
else
button_mc.onEnterFrame = animateOut;
}
}

// Method called by the enterframe event to animate the clip over
function animateOver ():Void
{
if (this._currentframe < this._totalframes)
this.nextFrame ();
else
delete this.onEnterFrame;
}

// Method called by the enterframe event to animate the clip out
function animateOut ():Void
{
if (this._currentframe > 1)
this.prevFrame ();
else
delete this.onEnterFrame;
}

Matthew Torneo
08-29-2005, 08:21 PM
It works just like it does now, works ok but if you roll out quickly (which most people do) it still won't rollout.

Scottae
08-29-2005, 08:35 PM
That's because the buttons are so close to the edge of the Flash movie. There is no event that tells you when user rolls off the Flash movie itself. You will have to make some more room between button edge and the Flash movie edge. Also, instead of onEnterFrame, you could try using onMouseMove (http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary552.html)

onMouseMove = checkOut;

Matthew Torneo
08-30-2005, 03:13 PM
Well, it makes sense what you said about the buttons being so close to the end of the Flash so I increased the height of the document and it seems to be solving the problem.

Thanks so much for the help.

HairInTheSoup
09-16-2005, 01:20 AM
Hi,

I want to apologize first for linking my question to this thread; itīs because the problem is similar but i need some other advice. And here is the problem: I have an invisible button and below it thereīs a movieclip (a bit smaller than the button). I have some script in the button that tells the movie what to do on roll over and roll out:

on (rollOver) {
movie_boton_eventos.play(1)
}
on (rollOut) {
movie_boton_eventos.play(6)
}

The problem is that if I roll over or out too quickly the movieclip doesnīt respond, or it does partially. :strain: In http://www.flashlevel.net/ there are buttons that work great, no matter the speed I put to the mouse.

Thank you