Re: [Flashcoders] private constructors in AS3.0?

2006-07-10 Thread eka

Hello :)

use internal keyword it's more easy :
http://groups.google.com/group/FCNG/browse_thread/thread/b16a38f8389803a0/8ff037af609e7b94#8ff037af609e7b94

text\Singleton.as
--
package test
   {

   public const Singleton:_Singleton = new _Singleton();

   }

internal class _Singleton
   {
   function _Singleton()
   {

   }

   public const testconst:String = hello world;

   public var testvar:String = bonjour le monde;

   public function testMethod():String
   {
   return ni hao shijie;
   }
   }
--

testSingleton2.as
--
package
   {
   import flash.display.Sprite;

   import test.Singleton;

   public class testSingleton2 extends Sprite
   {

   public function testSingleton2()
   {
   trace( Singleton.testconst );
   trace( Singleton.testvar );
   trace( Singleton.testMethod() );
   }
   }
   }

Thanks Zwetan for this good solution.

EKA+ :)

2006/7/10, Weyert de Boer [EMAIL PROTECTED]:


I am told private constructors should jsut work fine (in AS2 though)
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] private constructors in AS3.0?

2006-07-09 Thread Cédric Néhémie
Hi,

I've trying to create singleton, and the best way i've fund is to create
the instance direcly in the class declaration

private static var _oInstance:MyClass = getInstance();

And to check if constructor is called in code I do that :

public function MyClass ()
{
if (_oInstance == null)
throw new IllegalOperationError (MyClass is a singleton, and an
instance allready exist. Use getInstance to get a reference to the
instance);
}

In that way an instance is automatically created and every call of the
constructor will throw an error. If you don't want to have an instance
at start, but only when getInstance is called it's a bit less proper :

private static var _bInstanciable:Boolean = false;
private static var _oInstance:MyClass;

public function MyClass ()
{
if(!_bInstanciable)
   throw new IllegalOperationError (MyClass is a singleton, and an
instance allready exist. Use getInstance to get a reference to the
instance);
}
public static function getInstance ():MyClass
{
if(_oInstance == null)
{
_bInstanciable = true;
_oInstance = new MyClass();
_bInstanciable = false;
}
return _oInstance;
}
 Hi,

 This might be old stuff but I missed it completely ... I was wondering if
 somebody can tell me the rationale about that constructors in AS3.0 must be
 public and what happens to Singletons in AS3.0?

 Thanks,
 Sascha



 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com


   

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] private constructors in AS3.0?

2006-07-09 Thread elibol

That is nice, I like how you can assign functions to compile time variables.

On 7/9/06, Cédric Néhémie [EMAIL PROTECTED] wrote:


Hi,

I've trying to create singleton, and the best way i've fund is to create
the instance direcly in the class declaration

private static var _oInstance:MyClass = getInstance();

And to check if constructor is called in code I do that :

public function MyClass ()
{
if (_oInstance == null)
throw new IllegalOperationError (MyClass is a singleton, and an
instance allready exist. Use getInstance to get a reference to the
instance);
}

In that way an instance is automatically created and every call of the
constructor will throw an error. If you don't want to have an instance
at start, but only when getInstance is called it's a bit less proper :

private static var _bInstanciable:Boolean = false;
private static var _oInstance:MyClass;

public function MyClass ()
{
if(!_bInstanciable)
   throw new IllegalOperationError (MyClass is a singleton, and an
instance allready exist. Use getInstance to get a reference to the
instance);
}
public static function getInstance ():MyClass
{
if(_oInstance == null)
{
_bInstanciable = true;
_oInstance = new MyClass();
_bInstanciable = false;
}
return _oInstance;
}
 Hi,

 This might be old stuff but I missed it completely ... I was wondering
if
 somebody can tell me the rationale about that constructors in AS3.0 must
be
 public and what happens to Singletons in AS3.0?

 Thanks,
 Sascha



 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com




___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] private constructors in AS3.0?

2006-07-09 Thread Cédric Néhémie
Just a little error in the first code, it's not :

if (_oInstance == null)

but :

if (_oInstance != null)

I think you have rectify by yourself ;)
 That is nice, I like how you can assign functions to compile time
 variables.

 On 7/9/06, Cédric Néhémie [EMAIL PROTECTED] wrote:

 Hi,

 I've trying to create singleton, and the best way i've fund is to create
 the instance direcly in the class declaration

 private static var _oInstance:MyClass = getInstance();

 And to check if constructor is called in code I do that :

 public function MyClass ()
 {
 if (_oInstance == null)
 throw new IllegalOperationError (MyClass is a singleton, and an
 instance allready exist. Use getInstance to get a reference to the
 instance);
 }

 In that way an instance is automatically created and every call of the
 constructor will throw an error. If you don't want to have an instance
 at start, but only when getInstance is called it's a bit less proper :

 private static var _bInstanciable:Boolean = false;
 private static var _oInstance:MyClass;

 public function MyClass ()
 {
 if(!_bInstanciable)
throw new IllegalOperationError (MyClass is a singleton, and an
 instance allready exist. Use getInstance to get a reference to the
 instance);
 }
 public static function getInstance ():MyClass
 {
 if(_oInstance == null)
 {
 _bInstanciable = true;
 _oInstance = new MyClass();
 _bInstanciable = false;
 }
 return _oInstance;
 }
  Hi,
 
  This might be old stuff but I missed it completely ... I was wondering
 if
  somebody can tell me the rationale about that constructors in AS3.0
 must
 be
  public and what happens to Singletons in AS3.0?
 
  Thanks,
  Sascha
 
 
 
  ___
  Flashcoders@chattyfig.figleaf.com
  To change your subscription options or search the archive:
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
  Brought to you by Fig Leaf Software
  Premier Authorized Adobe Consulting and Training
  http://www.figleaf.com
  http://training.figleaf.com
 
 
 

 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com

 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] private constructors in AS3.0?

2006-07-09 Thread Weyert de Boer

I am told private constructors should jsut work fine (in AS2 though)
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com