flash on 2009-9-30

by mmlemon_
TextFieldとgraphicsでかかれたアイテムのサイズとwidth, heightが

返す値との兼ね合いがわからなくなったので確認用に作成
♥0 | Line 46 | Modified 2009-09-30 15:10:28 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.text.*;
    import flash.events.*;
    /**
    TextFieldとgraphicsでかかれたアイテムのサイズとwidth, heightが
   
    返す値との兼ね合いがわからなくなったので確認用に作成
    */
    public class FlashTest extends Sprite {
        
        
        private var container:Sprite;
        private var boxes:Vector.<Box>;
        
        public function init():void
        {
           container = new Sprite();
           addChild(container);
           var box:Box = new Box();
           container.addChild(box);
            
        }
        
        public function FlashTest() {
            // write as3 code here..
            init();
        }
    }
}

import flash.display.*;
import flash.text.*;
import flash.events.*;

class Box extends Sprite
{
    
    private var tf:TextField;
    
    private function init():void
    {
        tf = new TextField();
        addChild(tf);
        tf.text = "aaaa";
        var format:TextFormat = new TextFormat();
        format.size = 20;
        tf.setTextFormat(format);
        tf.selectable = false;
        tf.width = 100;
        tf.height = 24;
        tf.text = tf.width.toString() + " h:" + tf.height.toString();
        this.graphics.beginFill(0xff0000, 1);
        this.graphics.drawRect(0, 0, 100, 20);
        this.graphics.endFill();
    }
    
    public function Box():void
    {
        init();
    }
}