Object Visualizer

by hemingway
♥0 | Line 206 | Modified 2013-03-07 03:37:45 | MIT License
play

ActionScript3 source code

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

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    
    public class Main extends Sprite
    {
        public function Main()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            Buffer.initContext(this);
            
            graphics.clear();
            graphics.lineStyle(1);
            graphics.drawRect(0, 0, stage.stageWidth-1, stage.stageHeight-1);
        }
    }
}

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

class Buffer
{
    public static var INSTANCE_CONTEXT :Object;
    
    public static function initContext($context:Object) :void
    {
        INSTANCE_CONTEXT = $context;
        
        $context.addChild(new Button(10, 10));
    }
}

class Button extends Sprite
{
    private var _buttonText :Output;    
    
    protected var _x :int;
    protected var _y :int;
    protected var _width :int;
    protected var _height :int;
    protected var _color :int;
    protected var _alpha :int;
    
    public function Button($x:int, $y:int)
    {
        addEventListener(Event.ADDED_TO_STAGE, addedToStage);
        
        _x = $x;
        _y = $y;
        _width = 86;
        _height = 20;
        _alpha = 1;
        _color = 0x666666;
        
        _buttonText = new Output("New Object", 0, 1, 0xFFFFFF);
    }
    
    public function addedToStage($e:*) :void
    {
        removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
        
        addChild(_buttonText);
        
        init();

        addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
        addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        addEventListener(MouseEvent.MOUSE_OUT, onMouseUp);
    }
    
    public function init() :void
    {
        graphics.clear();
        graphics.lineStyle(1);
        graphics.beginFill(_color, _alpha);
        graphics.drawRect(_x, _y, _width, _height);
        graphics.endFill();
        
        _buttonText.x = (_x + (_width/2) - (_buttonText.width/2));
        _buttonText.y = (_y + (_height/2) - (_buttonText.height/2));
    }
    
    public function onMouseDown($e:MouseEvent) :void
    {
        _color = 0xDDDDDD;
        _buttonText.color = 0;
        init();
    }
    
    public function onMouseUp($e:MouseEvent) :void
    {
        _color = 0x666666;
        _buttonText.color = 0xFFFFFF;
        init();
        
        buttonAction();
    }
    
    public function buttonAction() :void
    {
        
    }
    
    public function get color() :Number
    {return _color}
    public override function get alpha() :Number
    {return _alpha}
    public override function get x() :Number
    {return _x}
    public override function get y() :Number
    {return _y}
    
    public function set color($:Number) :void
    {_color = $; init()}
    public override function set alpha($:Number) :void
    {_alpha = $; init()}
    public override function set x($:Number) :void
    {_x = $; init()}
    public override function set y($:Number) :void
    {_y = $; init()}
}

class Output extends TextField
{
    private var _textFormat :TextFormat;
    
    protected var _x :Number;
    protected var _y :Number;
    protected var _font :String;
    protected var _size :Number;
    protected var _color :Number;
    protected var _content :String;
        
    public function Output($content:String, $x:Number = 1, $y:Number = 0, $color:Number = 0, $size:Number = 14, $font:String = "Helvetica")
    {
        addEventListener(Event.ADDED_TO_STAGE, addedToStage);
        
        _x = $x;
        _y = $y;
        _font = $font;
        _size = $size;
        _color = $color;
        _content = $content;
        
        selectable = mouseEnabled = false;
        autoSize = TextFieldAutoSize.LEFT;
        antiAliasType = AntiAliasType.ADVANCED;
    }
    
    public function addedToStage($e:Event) :void
    {
       removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
       
       _init(); 
    }
    
    public function _init() :void
    {
        x = _x;
        y = _y;
        text = _content;
        _textFormat = new TextFormat(_font, _size, _color);
        setTextFormat(_textFormat);
    }
    
    public function get font() :String
    { return _font }
    public function get nWidth() :Number
    { return width }
    public function get color() :Number
    { return _color }
    
    public function set font($:String) :void
    { _font = $; _init() }
    public function set content($:String) :void
    { _content = $; _init() }
    public function set color($:Number) :void
    { _color = $; _init() }
}

class Input extends TextField
{
    private var _textFormat :TextFormat;
    
    protected var _x :int;
    protected var _y :int;
    protected var _width :int;
    protected var _height :int;
    protected var _font :String;
    protected var _size :Number;
    protected var _content :String;
        
    public function Input($content:String, $x:int = 1, $y:int = 0, $width:int = 124, $height:int = 20, $size:Number = 14, $font:String = "Helvetica")
    {
        addEventListener(Event.ADDED_TO_STAGE, addedToStage);
        
        _x = $x;
        _y = $y;
        _width = $width;
        _height = $height;
        _font = $font;
        _size = $size;
        _content = $content;
        _textFormat = new TextFormat(_font, _size);
        
        border = true;
        background = true;
        backgroundColor = 0xDDDDDD;
        type = TextFieldType.INPUT;
        defaultTextFormat = _textFormat;
        antiAliasType = AntiAliasType.ADVANCED;
    }
    
    public function addedToStage($e:Event) :void
    {
       removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
       
       _init(); 
       
       addEventListener(FocusEvent.FOCUS_IN, onFocus);
    }
    
    public function _init() :void
    {
        x = _x;
        y = _y;
        width = _width;
        height = _height;
        text = _content;
    }
    
    public function onFocus($e:FocusEvent) :void
    {
        ((text == "_dialogUserInput") || (text == "_dialogPassInput")) ? text = "" : null;
    }
    
    public function get font() :String
    { return _font }
    public function get nWidth() :Number
    { return width }
    
    public function set font($:String) :void
    { _font = $; _init() }
    public function set content($:String) :void
    { _content = $; _init() }
}