flash on 2010-8-21

by kihon
♥0 | Line 37 | Modified 2010-08-21 01:52:28 | MIT License
play

ActionScript3 source code

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

package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    
    public class Main extends Sprite
    {    
        private const WIDTH:int = 50;
        private const HEIGHT:int = 50;
        private var tf:TextField;
        
        public function Main()
        {
            graphics.lineStyle(2.0);
            for (var y:int = 0; y < 400; y += HEIGHT)
            {
                for (var x:int = 0; x < 400; x += WIDTH)
                {
                    graphics.drawRect(x, y, WIDTH, HEIGHT);
                }
            }
            
            tf = new TextField();
            tf.defaultTextFormat = new TextFormat("Consolas,メイリオ,_typeWriter", 20, 0x0, true);
            tf.autoSize = "left";
            tf.x = 150;
            tf.y = 420;
            addChild(tf);
            
            stage.addEventListener(MouseEvent.CLICK, onMouseClick);
        }
        
        private function onMouseClick(event:MouseEvent):void 
        {
            var ty:int = mouseY / HEIGHT;
            var tx:int = mouseX / WIDTH;
            
            tf.text = "y = " + ty + " : x = " + tx;
        }
    }
}