It's a workaround for Flash creating an instance of my component without
running my init() method when the component is dragged onto the stage. I
had posted that problem on here a couple of weeks ago and this solution had
helped prevent from creating a second. I was using the Singleton like from
EAS p 382. If I remember correctly the constructor was being called despite
being private when the component was dragged on the stage- this would result
in a first instance of the class being created without running the line of
code that was setting my _myManager value to reference the class.
On 2/20/06, Isaac Rivera <[EMAIL PROTECTED]> wrote:
>
> I do not understand your implementation of this pattern.
>
> Classically, in single-threaded environments like the flash player,
> Singleton is implemented as below (using your nomenclature):
>
> class MyManager {
> private static _myManager: MyManager = null;
>
> public static function getInstance(): MyManager {
> if(_myManager == null) {
> _myManager = new MyManager();
> }
> return _myManager;
> }
>
> private function MyManager() {
> // constructor stuff here...
> }
> }
>
> This works. I use it regularly.
>
> The strange bit in your code is:
>
> > if(_myManager==null){
> > _myManager=this;
> > }
>
> Since _myManager is a PRIVATE and STATIC property set JUST BEFORE
> calling the constructor the FIRST TIME, why should the constructor
> attempt to set it? Specially when it does so as an instance property
> (ie. Not declaring the Class scope first as in:
>
> MyManager._myManager = this;
>
> What is the advantage of this block?
>
> izk
>
> On Feb 20, 2006, at 9:14 AM, Manuel Saint-Victor wrote:
>
> > Jesse,
> > Here is the getInstance that I am using
> >
> >
> > private function MyManager() {
> > // constructor
> > if(_myManager==null){
> >
> > _myManager=this;
> > }
> >
> > init();
> > }
> >
> > public static function getInstance() : MyManager{
> > if(_myManager==null){
> >
> > _myManager=new MyManager();
> > }
> > return _myManager;
> > }
> >
> >
> >
> > I switched the name of the class a bit but everything else is
> > unchanged in
> > these two methods.
> >
> > Mani
> > _______________________________________________
> > [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