button

by bujal
♥0 | Line 52 | Modified 2011-08-13 01:05:54 | MIT License
play

ActionScript3 source code

/**
 * Copyright bujal ( http://wonderfl.net/user/bujal )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fCyJ
 */

package {
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import com.greensock.TweenLite;
    import com.greensock.easing.*;
    public class FlashTest extends Sprite {
        public function FlashTest() {

            function createButton(str:String):MovieClip
            {
                var btn:MovieClip=new MovieClip();
                var background:MovieClip=new MovieClip();
                background.name='background';
                background.graphics.beginFill(0x0085C3);
                background.graphics.drawRect(0,0,100,-30);
                background.graphics.endFill();
                btn.addChild(background);
                background.y=30;
                var tf:TextFormat=new TextFormat();
                tf.color=0xFFFFFF;
                tf.size=12;
                tf.align='center';
                tf.font='Arial';
                var txt:TextField=new TextField();
                txt.defaultTextFormat=tf;
                txt.text=str;
                txt.width=100;
                txt.y=5;
                txt.selectable=false;
                btn.addChild(txt);
                btn.mouseChildren=false;
                btn.buttonMode=true;
                btn.addEventListener(MouseEvent.ROLL_OVER,btnRollOverEventListener);
                btn.addEventListener(MouseEvent.ROLL_OUT,btnRollOutEventListener);
                return btn
            }
            function btnRollOverEventListener(e:MouseEvent):void
            {
                TweenLite.to(e.target.getChildByName('background'),0.5,{height:50,ease:Back.easeOut});
            }
            function btnRollOutEventListener(e:MouseEvent):void
            {
                TweenLite.to(e.target.getChildByName('background'),0.2,{height:30,ease:Back.easeIn});
            }
            var mc:MovieClip=createButton('button1');
            addChild(mc);
            mc.y=100;
        }
    }
}

Forked