Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 24-06-2009
Member
 
Join Date: Jun 2009
Posts: 8
Singleton in AS2

Hiya

I'm struck with a question about implementing a Singleton class in AS2. I'm doing a project on nav/tracking frame, for that i need only one instance of the shell class.
this is the method that ever noted
mySingleton.getInstance().doMethod();

Wouldn't it be easier to make doMethod a static function?
mySingleton.doMethod();

Also, if I want to assign my lone class to a _global var, does that cause any problems? And how can i do

import com.MyClass;
_global.shell = MyClass; is this actual way?

thanks.....
Reply With Quote
  #2  
Old 24-06-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Singleton in AS2

Normally we all use a Singleton when you want to access a class from multiple places,indeed you should make sure that all those references point to a single instance of the class

but on the same time, static class methods are called on the class itself, and have no instance at alll. Static methods are better for one time function calls, that do not rely on retaining data between calls

now If you want to go for the Singleton method, no need to make it a global variable,because any object that references mySingleton.getInstance() will return the same instance of the Singleton object....

good for you.....
Reply With Quote
  #3  
Old 24-06-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Singleton in AS2

Well many times when you need only one instance of an object.In fact in many cases Singletons are the core classes of the Model View Controller Pattern,which is core to just about every Flash Application you’ll ever create.
Further, it may be inappropriate, resource hungry or less efficient to have multiple instances.
Reply With Quote
  #4  
Old 24-06-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Singleton in AS2

For abstract classes, it's not supported, never have been, but still confused
whether or not they ever will be in ActionScript.
Trying to create them anyway using runtime exceptions just seems ridiculous to me..
If you are going to use ActionScritp, then learn ActionScript and program in ActionScript. When you program in, python, you have a different mindset, different tools and features than you do ......
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Singleton in AS2"
Thread Thread Starter Forum Replies Last Post
Exception Handling in Singleton Bottlenecked Software Development 6 20-09-2010 09:14 PM
Serializable Singleton Implementation in Java Bhardwaj Software Development 5 18-02-2010 07:17 PM
Program for singleton objects which returns two instances Sarfaraj Khan Software Development 5 02-02-2010 12:37 PM
Single instance of singleton for all JVMs KANAN14 Software Development 3 30-10-2009 07:10 PM
What is a Singleton in java? Bhim Software Development 3 02-03-2009 08:18 PM


All times are GMT +5.5. The time now is 06:29 AM.