Creating an animated button with a MovieClip.

In: Flash & AS

9 Sep 2008

Have you ever seen a flash button that have transitions between RollOver and RollOut? Well, this thing is done by creating an animated movieclip with a little bit of actionscript:

  1. First, create a movieclip, and inside create your button design: a square shape with a text field or anything you want.
  2. Edit this movie clip.
  3. Create an animation with your shape and text inside this movie clip.
  4. Then, insert a new layer in this movie clip, and insert this ActionScript in the first frame
    //all this code is inside the complex button so you can stick as many as you want
    //on the stage and all will work.. they all will have this code in it..
    
    stop(); // stop the movie clip from playing (stop button from growing, we want that when the mouse rolls over only
    
    this.onEnterFrame = function(){
    if(rewind == true){   //if rewind switch is set to true play backwards
    prevFrame();        // play backwards
    }
    }
    
    this.onRollOver = function(){
    rewind = false; //set variable (or switch) that decides wether ot not to play backwards...
    play();    // play this movie clip.. (grow the button(tween));
    }
    
    this.onRollOut = function(){
    rewind = true;    //set or rewind switch to true so it will play backwards...
    }
    

  5. Now create a Keyframe at the end of the animation in this Layer, and insert a stop(); in the Actionscript panel.
  6. And finally, save the document, publish it, and test it!

And here are the source files:

Flash 9 ActionScript 2 file: mclip.fla

Swf File: mclip1.swf

Comment Form

About this blog

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque sed felis. Aliquam sit amet felis. Mauris semper, velit semper laoreet dictum, quam diam dictum urna, nec placerat elit nisl in quam. Etiam augue pede, molestie eget, rhoncus at, convallis ut, eros. Aliquam pharetra.

Photostream

    DSC06361DSC06325DSC06313DSC06298DSC06296DSC06295DSC06294DSC06288

Categories

Archives

Categories

Facebook Activity