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

TextSize確認君

Get Adobe Flash player
by umhr 02 Nov 2011
    Embed
/**
 * Copyright umhr ( http://wonderfl.net/user/umhr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zgKG
 */

package  
{
    
    import flash.display.Sprite;
    import flash.events.Event;
    /**
     * ...
     * @author umhr
     */
    public class WonderflMain extends Sprite 
    {
        
        public function WonderflMain() 
        {
            init();
        }
        private function init():void 
        {
            if (stage) onInit();
            else addEventListener(Event.ADDED_TO_STAGE, onInit);
        }
        
        private function onInit(event:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, onInit);
            // entry point
            
            stage.scaleMode = "noScale";
            stage.align = "TL";
            
            addChild(new Canvas());
            
            
        }
    }
    
}

    import com.bit101.components.Label;
    import com.bit101.components.Style;
    import com.bit101.components.TextArea;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.text.TextFormat;
    /**
     * ...
     * @author umhr
     */
    class Canvas extends Sprite 
    {
        private var _textArea:TextArea;
        private var _layoutTF:TextField = new TextField();
        private var _fontChooser:FontChooser;
        private var _label:Label;
        public function Canvas() 
        {
            init();
        }
        private function init():void 
        {
            if (stage) onInit();
            else addEventListener(Event.ADDED_TO_STAGE, onInit);
        }
        
        private function onInit(event:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, onInit);
            // entry point
            
            Style.embedFonts = false;
            Style.fontName = "_等幅";
            Style.fontSize = 12;
            
            // 入力欄
            _textArea = new TextArea(this, 5, 5, "TextArea");
            _textArea.width = 455;
            _textArea.textField.type = "input";
            _textArea.addEventListener(Event.CHANGE, change);
            
            // フォント選択
            _fontChooser = new FontChooser();
            _fontChooser.addEventListener(Event.CHANGE, change);
            addChild(_fontChooser);
            
            // フォント名やサイズ表示ラベル
            _label = new Label(this);
            _label.x = 5;
            _label.y = 284;
            
            // 流し込み結果
            _layoutTF.border = true;
            _layoutTF.defaultTextFormat = new TextFormat("_sans", 14);
            _layoutTF.multiline = true;
            _layoutTF.autoSize = "left";
            _layoutTF.x = 5;
            _layoutTF.y = 300;
            addChild(_layoutTF);
            
            _textArea.text = "ABCdefg1234あいうえおかきくけこ";
            change(null);
        }
        
        private function change(event:Event):void 
        {
            _layoutTF.defaultTextFormat = new TextFormat(_fontChooser.fontName, _fontChooser.fontSize);
            _layoutTF.text = _textArea.text;
            
            var tempText:String = _layoutTF.text;
            //改行などを除いた文字数をカウントするために。
            tempText = tempText.replace(/\n|\r|\t/g, "");
            
            var text:String = "";
            text += "FontName:" + _fontChooser.fontName;
            text += ", FontSize:" + _fontChooser.fontSize;
            text += ", 文字数:" + String(tempText.length);
            text += ", W:" + String(_layoutTF.width) + "px";
            text += ", H:" + String(_layoutTF.height) + "px";
            _label.text = text;
            
        }
        
    }

    import com.bit101.components.List;
    import com.bit101.components.NumericStepper;
    import com.bit101.components.VScrollBar;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.Font;
    
    /**
     * ...
     * @author umhr
     */
    class FontChooser extends Sprite 
    {
        public var fontName:String = "_等幅";
        public var fontSize:Number = 14;
        public function FontChooser() 
        {
            init();
        }
        
        private function init():void 
        {
            x = 5;
            y = 115;
            
            var list:com.bit101.components.List = new com.bit101.components.List(this, 0, 0, [ "_等幅", "_typewriter", "_ゴシック", "_sans", "_明朝", "_serif"]);
            list.selectedIndex = 0;
            list.width = 200;
            list.height = 160;
            list.addEventListener(Event.SELECT, list_select);
            
            var fontList:Array/*Font*/ = Font.enumerateFonts(true);
            var n:int = fontList.length;
            for (var i:int = 0; i < n; i++) 
            {
                list.addItem(fontList[i].fontName);
            }
            
            //fontList[i].fontType
            
            var numericStepper:NumericStepper = new NumericStepper(this, 220);
            numericStepper.value = fontSize;
            numericStepper.addEventListener(Event.CHANGE, numericStepper_select);
        }
        
        private function numericStepper_select(event:Event):void 
        {
            var numericStepper:NumericStepper = event.target as NumericStepper;
            fontSize = numericStepper.value;
            dispatchEvent(new Event(Event.CHANGE));
        }
        
        private function list_select(event:Event):void 
        {
            var list:com.bit101.components.List = (event.target as com.bit101.components.List);
            
            // 次の指定だとスクロールしてもの選択位置が移動しない。
            //fontName = _list.selectedItem.toString();
            
            var vScrollBar:VScrollBar = list.getChildAt(1) as VScrollBar;
            var num:int = list.selectedIndex + vScrollBar.value;
            fontName = list.items[num];
            dispatchEvent(new Event(Event.CHANGE));
        }
        
    }