ロールオーバーで文字色と背景色を切り替える

by yun
♥0 | Line 35 | Modified 2010-09-03 20:34:12 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.events.MouseEvent;
    
    public class MyTextField extends Sprite {
        public var fld:TextField;
        public function MyTextField() {
            // Text Field
            fld = new TextField();
            fld.x = 50;
            fld.y = 50;
            fld.autoSize = TextFieldAutoSize.LEFT;
            fld.background = true;
            fld.backgroundColor = 0xFFFFFF;
            // The format is set before the text is set.
            var tf:TextFormat = new TextFormat();
            tf.font = "_typewriter";
            tf.size = 18;
            fld.defaultTextFormat = tf;
            fld.text = "It discolors in the rollover.";
            addChild(fld);
            // The text cannot be selected with the mouse.
            fld.selectable = false;
            // Setting of rollover event.
            fld.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
            fld.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
        }
        public function rollOverHandler(event:MouseEvent):void {
            // Setting of text color and background color
            fld.textColor = 0xFFFFFF;
            fld.backgroundColor = 0x000000;
        }
        public function rollOutHandler(event:MouseEvent):void {
            // Setting of text color and background color
            fld.textColor = 0x000000;
            fld.backgroundColor = 0xFFFFFF;
        }
    }
}

Forked