Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 253281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:44:54+00:00 2026-05-11T21:44:54+00:00

I figured out how to create a static method that is available everywhere, for

  • 0

I figured out how to create a static method that is available everywhere, for example:

UtilLib.as:

package
{   
     public final class UtilLib
     {  
          public static function getTimeStamp():uint
          {
               var now:Date = new Date();
               return now.getTime();
          }
     }
}

I can access this everywhere by doing UtilLib.getTimeStamp() – Now, I want to create a new staic method called log(msg:String). This should log a message to a multi-line inputfield.

The problem however is that this inputfield must be created somewhere and must be accessible and visible all the time, and I don’t want to pass it through the function parameters all the time as this would cause a lot of trouble (I’d have to pass it through objects aswell..).

So, how do I make a “public textfield” so my static log method can write to it?

UPDATE:
I now tried the following class, with a static constructor (I think). However, the textfield object is not showing. When I do an addChild(debugField) after creating it, it gives me error 1180.

Logger.as

package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class Logger extends Sprite
    {
        public static var debugField:TextField;

        /* static block */
        {
            trace("Logger initializing.");
            debugField = new TextField();
            debugField.width = 500;
            debugField.height = 100;
            debugField.x = 100;
            debugField.y = 400;
            debugField.background = true;
            debugField.backgroundColor = 0xFFFFFF;
            debugField.defaultTextFormat = new CustomTextFormat();
            debugField.mouseWheelEnabled = true;
            debugField.multiline = true;
            debugField.type = TextFieldType.DYNAMIC;
        }

        public static function log(msg:String):void
        {
            if (debugField) debugField.appendText(msg);
        }

    }
}

I initialize it like this:

var test:Logger = new Logger();
addChild(test);

And I log a new message like this:

Logger.log("test");

Unfortunately, the textField is not showing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:44:55+00:00Added an answer on May 11, 2026 at 9:44 pm

    Essentially you need:

    • somewhere to log a message which is globally accessible
    • the ability to update a text field whenever the log message changes

    A simple solution using objects could look like this:

    Example

    package {
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.events.Event;
    
        public class Example extends Sprite {
            private var messageLog:TextField;
    
            public function Example() {
                createTextField();
                MessageLogger.getInstance().addEventListener( MessageLogger.LOG, handleMessageLoggerUpdate );
                MessageLogger.getInstance().log( "Message!" );
            }
    
            private function handleMessageLoggerUpdate( event:Event ):void {
                messageLog.text = MessageLogger.getInstance().getLog();
            }
    
            private function createTextField():void {
                messageLog = new TextField();
                addChild( messageLog );
            }
        }
    }
    

    MessageLogger

    package {
        import flash.events.EventDispatcher;
        import flash.events.Event;
    
        public class MessageLogger extends EventDispatcher {
            private static var instance:MessageLogger;
            public static function getInstance():MessageLogger {
                if ( !instance ) {
                    instance = new MessageLogger( new InstanceKey() );
                }
                return instance;
            }
    
            public static var LOG:String = "MessageLoader#log";
    
            private var messageLog:String;
    
            public function MessageLogger(key:InstanceKey) {
                messageLog = "";
            }
    
            public function log( message:String ):void {
                messageLog += message;
                notify();
            }
    
            public function getLog():String {
                return messageLog;
            }
    
            private function notify():void {
                dispatchEvent( new Event( LOG ) );
            }
        }
    }
    class InstanceKey {}
    

    The important thing here is that a message can be logged from anywhere using

    MessageLogger.getInstance().log( "Your Message Here" );
    

    and anything can be notified of when a message has been logged using

    MessageLogger.getInstance().addEventListener( MessageLogger.LOG, listenerFunction );
    

    at any point the current message log can be obtained using

    MessageLogger.getInstance().getLog();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To detect the touch, in a view controller, you could… May 11, 2026 at 11:59 pm
  • Editorial Team
    Editorial Team added an answer You could dump the results of sp_columns to a temp… May 11, 2026 at 11:59 pm
  • Editorial Team
    Editorial Team added an answer You should probably test to know for sure, but if… May 11, 2026 at 11:59 pm

Related Questions

I'm trying to create a custom transition, to serve as a replacement for a
I've been reading the other questions dealing with master pages, but I didn't see
This really has my stumped today. I'm sure its simple, but... Here is my
I'd like to create a data table given a List using the CopyToDataTable method

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.