Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Singleton Class in flex

    • 0
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 345
    Comment on it

    SINGLETON CLASS

    In object-oriented programming , a singleton class is a class that can have only one object (an instance of the class) at a time. It's good when you only want one object across the whole of your application It is usually used in flex to add Global State to a project.In other words, It allows you to do things like set and have access to global variables from anywhere in your application.

    To access a variable from the Singleton class we use the following.

    private var model:Singleton = Singleton.getInstance();
    

    Full code goes here!

    <pre>public class Singleton
                {
    
                        private static var instance:Singleton = new Singleton();
    
                        public var flexData:String = "FirstApp";
                        public var userScore:int = 0;
    
                           public function Singleton()
                    {
                        if(instance)
                        {
            throw new Error ("new instance cannot be created");
                       }
                    }
    
                    public static function getInstance():Singleton
                    {
                        return instance;
                    }
                }
    

    Hope this will help you!!!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: