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

  • Home
  • SEARCH
  • 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 6351377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:59:36+00:00 2026-05-24T21:59:36+00:00

I have an AS3 Singleton: package { public class Singleton { public function Singleton(enforcer:SingletonEnforcer):void

  • 0

I have an AS3 Singleton:

package 
    {
        public class Singleton
        {
            public function Singleton(enforcer:SingletonEnforcer):void
            {
                if(!enforcer){throw new Error("Only one instance of Singleton Class allowed.");}
            }

            private static var _instance:Singleton;
            public static function getInstance():Singleton
            {
                if(!Singleton._instance)
                {
                    Singleton._instance=new Singleton(new SingletonEnforcer());
                }
                return Singleton._instance;
            }
        }
    }
class SingletonEnforcer{}

Consider prop and func() to be a property and method respectively of the Singleton class.

How should I access them?

1. Make them static and use this:

Singleton.getInstance();
Singleton.prop;
Singleton.func();

2. Not make them static and use this:

Singleton.getInstance().prop;
Singleton.getInstance().func();

Does it matter, or is it just visual prefference?

Thank you.

  • 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-24T21:59:38+00:00Added an answer on May 24, 2026 at 9:59 pm

    The reason to use a singleton instance is so that you can have class members used in a (relatively) static way.

    I won’t get into the arguments over whether or not to use a singleton here, there’s a very long debate over whether it’s a good pattern or not.

    Typically, when singletons are used, you store access to them in a local variable and use them like any other class instance. The primary difference, is instead of using:

    foo = new Foo();
    

    You use:

    foo = Foo.instance;
    //Actionscript supports properties which makes this a self-initializing call
    -or-
    foo = Foo.getInstance();
    

    Followed by

    foo.bar();
    foo.baz();
    foo.fizz = 'buzz';
    

    This doesn’t mean that Foo can’t have static members of the class, but the rules for adding static members on a Singleton are the same for adding static members to any other class. If the function belongs to the instance, it should be used on the instance, if it belongs to the class, it should be static.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an AS3 App class e.g (pseudo code) public class MyApp extends Application
I have as3 class like this package { import Global; import flash.display.MovieClip; import flash.events.*;
Many library classes in AS3 have read only properties. Is it possible to create
In AS3 you have a function on a string with this signature: function replace(pattern:*,
I'm new to AS3 and have been working on an XML driven navigation system
I have the following array as3 example: var arrayDefinitionsargsAmfPhp:Array = new Array(); arrayDefinitionsargsAmfPhp['tabela'] =
currently I'm having some problems with my preloader. I have an as3 class website
I have the following as3 function below which converts normal html with links so
I have two AS3 classes, A and B. Class A contains an ArrayCollection that
i have a problem using AS3 - Flash CS3 gives me this Error message:

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.