technicalcare
asked on
Expanding/Contracting Buttons on MouseOver/RollOut
Hi,
I am creating a navigation menu in Flash in which my client wants an animation for the buttons on mouse over and on mouse roll out. On mouse over, the button should grow taller, and on mouse roll out it should go back to the original size.
The problem I'm running into is that I know how to create a movie and insert it into the "Over" tab of the button menu, but I cannot get the animation to slowly return to it's original dimensions. Instead, it just snaps back to the starting shape abruptly, which is something I want to avoid.
I've tried coding for ScaleX and ScaleY, but I'm a novice at flash, especially the ActionScript part. I also found the following code on this site, but am unaware of how to implement it.
on (rollOver) {
this.gotoAndPlay("up");
}
on (rollOut) {
this.gotoAndPlay("down");
}
In both cases, the button just flickers and does not grow as it should.
Any help would be greatly appreciated, and while I await an answer I'll keep looking for new ways to get this working.
I am creating a navigation menu in Flash in which my client wants an animation for the buttons on mouse over and on mouse roll out. On mouse over, the button should grow taller, and on mouse roll out it should go back to the original size.
The problem I'm running into is that I know how to create a movie and insert it into the "Over" tab of the button menu, but I cannot get the animation to slowly return to it's original dimensions. Instead, it just snaps back to the starting shape abruptly, which is something I want to avoid.
I've tried coding for ScaleX and ScaleY, but I'm a novice at flash, especially the ActionScript part. I also found the following code on this site, but am unaware of how to implement it.
on (rollOver) {
this.gotoAndPlay("up");
}
on (rollOut) {
this.gotoAndPlay("down");
}
In both cases, the button just flickers and does not grow as it should.
Any help would be greatly appreciated, and while I await an answer I'll keep looking for new ways to get this working.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I appreciate the answers, guys. However, I'm having some issues integrating your code in my file. I notice the first code is for CS3 AS2, but I am using CS4 and AS3, and probably should have mentioned that in my original post.
I tried to use the second poster's code, but I'm having problems that I believe stem from the first two lines that import mx.transitions. I'm getting the following script errors:
1172: Definition mx.transitions:Tween could not be found.
1172: Definition mx.transitions.easing could not be found.
1172: Definition mx.transitions:Tween could not be found.
1172: Definition mx.transitions.easing could not be found.
1046: Type was not found or was not a compile-time constant: Tween.
1180: Call to a possibly undefined method Tween.
1120: Access of undefined property Strong.
1120: Access of undefined property button_height_original.
1120: Access of undefined property button_height_stretch.
1119: Access of possibly undefined property onRollOver through a reference with static type flash.display:SimpleButton .
1119: Access of possibly undefined property onRollOut through a reference with static type flash.display:SimpleButton .
1119: Access of possibly undefined property onRelease through a reference with static type flash.display:SimpleButton .
1119: Access of possibly undefined property onReleaseOutside through a reference with static type flash.display:SimpleButton .
1120: Access of undefined property button_height_stretch.
1120: Access of undefined property button_height_original.
1120: Access of undefined property button_height_original.
1120: Access of undefined property button_height_original.
Warning: 1090: Migration issue: The onRollOver event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'mouseOver', callback_handler).
There are 4 of those last migration issues, so I'm assuming that my problem is also having to do with AS3. Any ideas on how to fix those for AS3 so that I can get this up and running?
Thanks again, guys!
I tried to use the second poster's code, but I'm having problems that I believe stem from the first two lines that import mx.transitions. I'm getting the following script errors:
1172: Definition mx.transitions:Tween could not be found.
1172: Definition mx.transitions.easing could not be found.
1172: Definition mx.transitions:Tween could not be found.
1172: Definition mx.transitions.easing could not be found.
1046: Type was not found or was not a compile-time constant: Tween.
1180: Call to a possibly undefined method Tween.
1120: Access of undefined property Strong.
1120: Access of undefined property button_height_original.
1120: Access of undefined property button_height_stretch.
1119: Access of possibly undefined property onRollOver through a reference with static type flash.display:SimpleButton
1119: Access of possibly undefined property onRollOut through a reference with static type flash.display:SimpleButton
1119: Access of possibly undefined property onRelease through a reference with static type flash.display:SimpleButton
1119: Access of possibly undefined property onReleaseOutside through a reference with static type flash.display:SimpleButton
1120: Access of undefined property button_height_stretch.
1120: Access of undefined property button_height_original.
1120: Access of undefined property button_height_original.
1120: Access of undefined property button_height_original.
Warning: 1090: Migration issue: The onRollOver event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'mouseOver', callback_handler).
There are 4 of those last migration issues, so I'm assuming that my problem is also having to do with AS3. Any ideas on how to fix those for AS3 so that I can get this up and running?
Thanks again, guys!
Yep you are right I am using AS2 in CS3 I will look to see if there is a Tween class equivalent in AS3 and repost.
Right I have adjusted the code to work in AS3. New file is at http://www.craybe.com.au/ButtonTweenAS3.fla and new code below:
all that changed is the import library (from mx to fl) the event handler from buttons (apparently you have to use listeners now) and some slight adjustments to the tween dimension lable.
Hope this helps :-)
all that changed is the import library (from mx to fl) the event handler from buttons (apparently you have to use listeners now) and some slight adjustments to the tween dimension lable.
Hope this helps :-)
import fl.transitions.Tween;
import fl.transitions.easing.*;
var button_height_original = 100
var button_height_stretch = 200
thebutton.addEventListener(MouseEvent.MOUSE_OVER, StretchOut);
thebutton.addEventListener(MouseEvent.MOUSE_OUT, StretchIn);
function StretchOut(evt:MouseEvent):void{
scalebutton(thebutton,button_height_stretch)
}
function StretchIn(evt:MouseEvent):void{
scalebutton(thebutton,button_height_original)
}
//this function will animate the button on the _yscale
function scalebutton(buttonvar,new_size){
//Tween(the button name, dimension to change, type of tween, original size, new size, speed
var button_tween:Tween = new Tween(buttonvar, "height", Strong.easeOut, buttonvar.height, new_size, 1, true);
}
ASKER
This works great Craybe, I just have one more question. How do I make the button expand upward instead of downward? These buttons will be at the bottom of the stage, so I need them to pop up rather than down. Once we get that in order, I'll be good to go!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great, I appreciate both of your help. Points inc.
ASKER
Really appreciate the help!
If you want to make it scale on the x axis just duplicate the line of code in the scalebutton function and change the tween name and "_yscale" to "_xscale"
You can download an example of the code (very basic) at http://www.craybe.com.au/ButtonTween.fla
Let me know if you would like more information on how to set up multiple buttons.
Open in new window