
Francis Baptiste
Graduate of Langara Electronice Media Design Program and Lagnara Publishing Program in Vancouver, BC, Canada. Practicing member of the GDC (Association of Graphic Designers of Canada). Freelance Actionscript developer and web designer currently living in Kelowna, BC, Canada.
View all articles by Francis BaptisteWhen designing in Flash, using a button symbol for an animated button presents several problem. The biggest problem for most designers being, if you put an animation in the roll over state, it'll snap back to the beginning once you roll out. Today I’ll show you one way you can approach animated buttons using a MovieClip and the nextFrame() and prevFrame() methods. The advantage to this method is when you hover on the button then mouse off, it’ll play backwards from wherever it is, instead of snapping to the beginning the way it would if you designed it using the built-in button symbols.
It’s a simple four-step process:
Step 1:
Create your movie clip animation. This can be anything at any length.
Usually 30 to 45 frames will do it. For my example I’ll just create a
black square that increases in width (lame, yes, but it gets the point
across). Add an instance of your movie clip to the stage. Give it an
instance name. I’m naming mine btn.
Step 2:
In your AS file (or in the timeline, if that’s where you’re writing
your code), set the button mode for your movie clip to true. Also, add
mouse event listeners for mouse over and mouse out.
btn.buttonMode = true;
btn.addEventListener(MouseEvent.MOUSE_OVER, onOver);
btn.addEventListener(MosueEvent.MOUSE_OUT, onOut);
Step 3:
Add a boolean, to say whether or not the mouse is hovering over your
button. Then write the functions for your mouse events, feeding a true
or false to the boolean.
var overBtn:Boolean = false;
function onOver(e:MouseEvent):void {
overBtn = true;
}
function onOut(e:MouseEvent):void {
overBtn = false;
}
Step 4:
In the actionscript, add an event listener for the enter frame event.
In your onEnter function add an if statement that says your movie clip
will go to the next frame if the mouse if over your button and to the
previous frame other wise.
addEventListener(Event.ENTER_FRAME, onEnter);
function onEnter (e:Event):void {
if(overBtn){
btn.nextFrame();
}else {
btn.prevFrame();
}
}
The advantage of doing your buttons like this is the button will play through your animation if your hovering, and when you move the mouse away it’ll play backward from where it is, instead of snapping back to the beginning, as it would if you’re using a built-in button symbol. It’s a good way to make smooth transitions. If you want to take it a step further, you can incorporate a tweening engine like Tweener or TweenLite to make things even smoother.
Spread The Word
19 Responses to "Movieclip Buttons with nextFrame() and prevFrame()" 
|
said this on 18 Feb 2010 10:49:57 AM CST
could use more instructio
some scr it's go |
|
said this on 04 Mar 2010 4:39:26 AM CST
Please see the script 3rd
Please correct it.. and tryed this scri anyway thanks |
|
said this on 05 Mar 2010 3:51:09 AM CST
provide screen shots step
|
|
said this on 12 Mar 2010 12:29:57 AM CST
Can you please add the ed
|
|
said this on 13 Mar 2010 7:43:30 AM CST
Very good and smart metho
It's really help me Thank you |
|
said this on 21 Mar 2010 11:58:52 PM CST
Can you please email me
tha |
|
said this on 24 Mar 2010 12:51:22 PM CST
I can't aplly to several
|
|
said this on 01 Apr 2010 9:29:28 AM CST
Can you email me the .fla
|
|
said this on 04 Apr 2010 2:54:43 PM CST
finally i got the animati
|
|
said this on 03 May 2010 7:19:54 AM CST
i tried doing this.. didn
I only get one |
|
said this on 08 May 2010 6:26:54 AM CST
Thanks, Francis Baptiste
It is Cr - Movieclip Button wi http://ww /* Code starts. Cod PrijatelBTN.buttonM PrijatelBTN. var overBtn:Boo function o (e:MouseEve addEventListener( function onEnter (e: if(overBt } else { }} */ Code ends. - Movieclip Buttons w http://w /* Code starts. Wo Prijat PrijatelBTN.addEventList P var o function onPrijatelBTNOv func addEventL f if(o } el }} prija prijatelMKD.addEventLis var function onpr onprijatelMKDOut(e:Mou a function onprijate if(overprijatelMKDBtn } else { }} */ Code ends Best regards. prija |
|
said this on 10 May 2010 10:37:15 AM CST
what would i need to add
|
|
said this on 13 May 2010 4:41:37 AM CST
Hi, i'm new to thhe Actio
|
|
said this on 16 Aug 2010 5:16:47 PM CST
Thank you very much for t
|
|
said this on 13 Oct 2010 7:43:47 PM CST
Well done mate, really go
Couple 1. Yeah, the 'mosue 2. Reason a 3. F In other words |
|
said this on 12 Nov 2010 6:48:51 AM CST
this is really cool tutor
|


Author/Admin)