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 1052269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:04:03+00:00 2026-05-16T17:04:03+00:00

Consider this scenario we have a class A which is singleton it has a

  • 0

Consider this scenario we have a class A which is singleton it has a function Sum(a,b) ** . Now we have two classes **Class B and Class C respectively. Both classes (B,C) call add function and listen for a event.

Class A
{
    function add(a:int,b:int):void
    {
        c:int = a+b;
        dispatchEvent(new myEvent(myEvent.addComplete,c));
    }

}

Class B
{
    function addSomething():void
    {
          var objectA:A = new A();
          objectA.addEventListener(myEvent,onAddComplete);
          var a:int = 10;
          var b:int = 20;
          objectA.add(a,b); 
    }

    function onAddComplete(e:myEvent):void
    {
              trace(e.something);
     }
}

Similarly there is a C and D class. Now when lets say both classes call A’s add function (when A is singleton) how does one insure that the right answer is returned to the right listener.

Secondly what if the calls are changing something, is there a locking in singleton?

  • 1 1 Answer
  • 4 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-16T17:04:03+00:00Added an answer on May 16, 2026 at 5:04 pm

    When you instantiate a Singleton, you don’t use “new” , otherwise it wouldn’t be a Singleton, you would keep creating instances of the A class. In order for your class to be a Singleton, only one instance can be created, this way , when you call A in other classes, you are calling the same instance of A.

    Generally you use the getInstance method which either return an instance of the Singleton class if none exist or return the previously created instance of A.

    Have a look at this for more information:
    http://www.gskinner.com/blog/archives/2006/07/as3_singletons.html

    It is generally accepted that Singleton should be avoided when possible. You should find a few posts here explaining why, here’s an example:

    What is so bad about singletons?

    In your example, you could do this for instance:

    class A
    {
       function add( params:Object , dispatcher:EventDispatcher )
        { 
           c = params.a + params.b;
           dispatcher.dispatchEvent( new MyEvent(c) );
      }
    }
    
    class B
    {
        private var _dispatcher:EventDispatcher = new EventDispatcher();
    
        function addSomething():void
        {
              var objectA:A = new A();
              _dispatcher.addEventListener(MyEvent.ADD,onAddComplete);
              var params:Object = {a:10 , b:20};
              objectA.add(params , _dispatcher); 
        }
    
        function onAddComplete(e:MyEvent):void
        {
                  trace(e.something);
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please Consider this scenario: We have a base class called clsMain : class clsMain
Can we have a model class which is singleton in Doctrine? For Singleton classes
Consider this scenario. I have some business logic that now and then will be
Consider this scenario: I have a project with two modules and one common module
Consider this scenario: You have a textbox in which you have to write some
Consider this scenario. I have my own website, that I use as my identifier,
Consider this scenario. I have an object, lets call it.... Foo. Foo raises a
Consider a grocery store scenario (I'm making this up) where you have FACT records
Consider, I have the following 3 classes / interfaces: class MyClass<T> { } interface
Consider I have the following classes: class User { [Key] public Guid Id {get;

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.