In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

SimpleButton

Get Adobe Flash player
by flashrod 19 Feb 2010
/**
 * Copyright flashrod ( http://wonderfl.net/user/flashrod )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jOea
 */

package {
    import flash.display.DisplayObject;
    import flash.display.GradientType;
    import flash.display.Shape;
    import flash.display.SimpleButton;
    import flash.display.Sprite;
    import flash.filters.BlurFilter;
    import flash.filters.DropShadowFilter;
    import flash.filters.GlowFilter;
    import flash.geom.Matrix;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    public class Hello extends Sprite {

        public function Hello() {
            var us:DisplayObject = createState(100, 40, 24, 24, 4, 0x0000FF, "OK");
            var os:DisplayObject = createState(100, 40, 24, 24, 4, 0x4444FF, "OK");
            var ds:DisplayObject = createState(100, 40, 24, 24, 0, 0x4444FF, "OK");
            ds.x = 4;
            ds.y = 4;
            var b:SimpleButton = new SimpleButton(us, os, ds, us);
            b.x = 100;
            b.y = 100;
            addChild(b);
        }

        /** ボタンの表示イメージを作ります。
         * @param w 幅
         * @param h 高さ
         * @param rx 角丸幅
         * @param ry 角丸高さ
         * @param d ドロップシャドウ距離
         * @param c 色
         * @param t ラベルテキスト
         */
        public static function createState(w:int, h:int, rx:int, ry:int, d:int, c:uint, t:String):DisplayObject {
            var s:Sprite = new Sprite();
            s.graphics.beginFill(c);
            s.graphics.drawRoundRect(0, 0, w, h, rx, ry);
            s.graphics.endFill();
            s.filters = [ new GlowFilter(0x000000, 1, 4, 4, 2, 1, true),
                          new DropShadowFilter(d, 45, 0, 0.5) ];

            var s1:Shape = new Shape();
            var m1:Matrix = new Matrix();
            m1.createGradientBox(w-4, h/2-4, Math.PI/2);
            s1.graphics.beginGradientFill(GradientType.LINEAR, [0xFFFFFF, 0xFFFFFF], [1, 0.25], [0, 255], m1);
            s1.graphics.drawRoundRect(0, 0, w-4, h/2-4, rx-2, rx-2);
            s1.graphics.endFill();
            s1.x = 2;
            s1.y = 2;
            s.addChild(s1);

            var s2:Shape = new Shape();
            var m2:Matrix = new Matrix();
            m2.createGradientBox(w-4-4, h/2-4, Math.PI/2);
            s2.graphics.beginGradientFill(GradientType.LINEAR, [0xFFFFFF, 0xFFFFFF], [0.05, 0.75], [0, 255], m2);
            s2.graphics.drawRoundRect(0, 0, w-4-4, h/2-4, rx-2, rx-2);
            s2.graphics.endFill();
            s2.filters = [ new BlurFilter(8, 8) ];
            s2.x = 2+2;
            s2.y = h/2+2;
            s.addChild(s2);

            var l:TextField = new TextField();
            l.autoSize = TextFieldAutoSize.LEFT;
            var tf:TextFormat = new TextFormat();
            tf.font = "Verdana";
            tf.bold = true;
            tf.color = 0xFFFFFF;
            tf.size = h/2;
            l.defaultTextFormat = tf;
            l.text = t;
            l.filters = [ new DropShadowFilter(4, 45, 0, 0.3) ];
            l.alpha = 0.9;
            l.x = (w-l.width)/2;
            l.y = (h-l.height)/2;
            s.addChild(l);

            return s;
        }
    }
}