forked from: button

by bujal forked from button (diff: 32)
♥0 | Line 76 | Modified 2011-08-16 18:58:14 | 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/ry19
 */

// forked from bujal's button
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.plugins.TweenPlugin;
    import com.greensock.plugins.BlurFilterPlugin;
    import com.greensock.TimelineLite;
    import com.greensock.easing.*;
    public class FlashTest extends Sprite {
        public function FlashTest() {

            function createButton(str:String):MovieClip
            {
                
                TweenPlugin.activate([BlurFilterPlugin]);
                var btn:MovieClip=new MovieClip();
                var background:MovieClip=new MovieClip();
                var background_mask:MovieClip=new MovieClip();
                background_mask.graphics.beginFill(0x00FF00);
                background_mask.graphics.drawRect(0,0,100,30);
                background_mask.graphics.endFill();
                btn.addChild(background_mask);
                background.mask=background_mask;
                background.name='background';
                background.graphics.beginFill(0x0085C3);
                background.graphics.drawRect(0,0,100,30);
                background.graphics.endFill();
                background.graphics.beginFill(0x000000);
                background.graphics.drawRect(0,0,100,-30);
                background.graphics.endFill();
                btn.addChild(background);
                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.height=30;
                txt.y=5;
                txt.selectable=false;
                txt.name='txt';
                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
            {
                var txt:TextField=e.target.getChildByName('txt');
                var background:MovieClip=e.target.getChildByName('background');
                var tl:TimelineLite=new TimelineLite();
                tl.insert(TweenLite.to(background,0.2,{y:30}),0);
                tl.insert(TweenLite.to(txt,0.2,{y:30,blurFilter:{blurY:20},ease:Back.easeIn}),0);
                tl.append(TweenLite.to(txt,0.01,{y:-30}));
                tl.append(TweenLite.to(txt,0.2,{y:30}));
                tl.append(TweenLite.to(txt,0.01,{y:-30}));
                tl.append(TweenLite.to(txt,0.2,{y:5,blurFilter:{blurY:0},ease:Back.easeOut}));
                tl.play();

            }
            function btnRollOutEventListener(e:MouseEvent):void
            {
                var background:MovieClip=e.target.getChildByName('background');
                TweenLite.to(background,0.2,{y:0});
            }
            var mc:MovieClip=createButton('button1');
            addChild(mc);
            mc.y=100;
        }
    }
}