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
>> >
>> >
>> >
>> > _______________________________________________
>> > [email protected]
>> > 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
>> >
>> >
>> >
>>
>> _______________________________________________
>> [email protected]
>> 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
>>
> _______________________________________________
> [email protected]
> 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
>
>

_______________________________________________
[email protected]
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

Reply via email to