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

LoggingAPI - TextFieldに出力

Get Adobe Flash player
by fff 31 May 2009
/**
 * Copyright fff ( http://wonderfl.net/user/fff )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/k2g4
 */

// forked from fff's LoggingAPI
package
{
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.utils.getTimer;
    
    import mx.logging.ILogger;
    import mx.logging.Log;
    import mx.logging.LogEventLevel;
    
    public class ASLogTest extends Sprite
    {
        private static const logger:ILogger = Log.getLogger("ASLogTest");
        
        public function ASLogTest()
        {
            initLogging();
            
            logger.info("コンストラクタ");
            
            var t:Timer = new Timer(500);
            t.addEventListener(TimerEvent.TIMER, function (event:TimerEvent):void
            {
                logger.debug("timer {0}", getTimer());
            });
            t.start();
        }
        
        private var tf:TextField;
        
        private var logTarget:BindableTarget;
        
        private function initLogging():void
        {
            // Create a target.
            logTarget = new BindableTarget();
            
            // Log only messages for the classes in the mx.rpc.* and 
            // mx.messaging packages.
        //    logTarget.filters=["mx.rpc.*","mx.messaging.*"];
            
            // Log all log levels.
            logTarget.level = LogEventLevel.ALL;
            
            // Add date, time, category, and log level to the output.
        //    logTarget.includeDate = true;
        //    logTarget.includeTime = true;
            logTarget.includeCategory = true;
            logTarget.includeLevel = true;
            
            // Begin logging.
            Log.addTarget(logTarget);
            
            
            logger.debug("initLogging");
            
            tf = new LogField(logTarget);
            tf.width = 200;
            tf.height = 200;
            addChild(tf);
        }
        
        
    }
}

import flash.text.TextField;
import mx.binding.utils.BindingUtils;

class LogField extends TextField
{
    public function LogField(target:BindableTarget)
    {
        border = true;
        
        updateLog(target.log);
        
    //    BindingUtils.bindProperty(this, "text", target, "log");
        BindingUtils.bindSetter(updateLog, target, "log");
    }
    
    private function updateLog(log:String):void
    {
        text = log;
        scrollV = maxScrollV;
    }
}


import mx.core.mx_internal;
import mx.logging.targets.LineFormattedTarget;
use namespace mx_internal;
    
class BindableTarget extends LineFormattedTarget
{
    [Bindable]
    public var log:String = "";
    
    override mx_internal function internalLog(message:String):void
    {
       log += message + "\n";
    }
}