Re: [Flashcoders] When singletons go bad

2006-02-20 Thread Manuel Saint-Victor
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
> > ___
> > 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] When singletons go bad

2006-02-20 Thread Isaac Rivera

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
___
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] When singletons go bad

2006-02-20 Thread JesterXL
Only in AS3, not AS2.  In AS2:

trace ( null == undefined ); // true

That's not his problem; that solution works fine.  Something else is 
failing.

It's been this way since like Flash 5.

- Original Message - 
From: "Morten Barklund TBWA\Play" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" 
Sent: Monday, February 20, 2006 9:40 AM
Subject: Re: [Flashcoders] When singletons go bad


Manuel Saint-Victor wrote:
> I had MyManager declared and in my variable declaration chunk up top but 
> had
> not added in the last part(=null)
>
> private static var _myManager : MyManager;
>
> I'm going to try changing that and see how if that helps.

That would exactly be the problem - as the variable is undefined when
not set - never null. Initialising to null or just casting to boolean in
the condition should fix the problem.

-- 
Morten Barklund - Information Architect - TBWA\Play
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
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] When singletons go bad

2006-02-20 Thread Morten Barklund TBWA\\Play

Manuel Saint-Victor wrote:

I had MyManager declared and in my variable declaration chunk up top but had
not added in the last part(=null)

private static var _myManager : MyManager;

I'm going to try changing that and see how if that helps.


That would exactly be the problem - as the variable is undefined when 
not set - never null. Initialising to null or just casting to boolean in 
the condition should fix the problem.


--
Morten Barklund - Information Architect - TBWA\Play
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
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] When singletons go bad

2006-02-20 Thread Manuel Saint-Victor
It's a workaround that someone suggested on the list earlier.  Because users
can drag and drop our components in some cases they were getting
instantiated without the static variable being set so they suggested
throwing in that as a way of preventing double instantiation.

I had MyManager declared and in my variable declaration chunk up top but had
not added in the last part(=null)

private static var _myManager : MyManager;

I'm going to try changing that and see how if that helps.


Mani



On 2/20/06, Morten Barklund TBWAPlay <[EMAIL PROTECTED]> wrote:
>
> Manuel Saint-Victor wrote:
> > if(_myManager==null){
>
> Nothing is null, unless explicitly set to null.
>
> And why do you check for the existence of the staticly set _myManager
> both in the static singleton-accessor and in the constructor - one of
> them should be enough.
>
> --
> Morten Barklund - Information Architect - TBWA\Play
> Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
> Phone: +45 7027 2227 - Fax: +45 3369 1174
> ___
> 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] When singletons go bad

2006-02-20 Thread Morten Barklund TBWA\\Play

Manuel Saint-Victor wrote:

if(_myManager==null){


Nothing is null, unless explicitly set to null.

And why do you check for the existence of the staticly set _myManager 
both in the static singleton-accessor and in the constructor - one of 
them should be enough.


--
Morten Barklund - Information Architect - TBWA\Play
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
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] When singletons go bad

2006-02-20 Thread Manuel Saint-Victor
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
___
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] When singletons go bad

2006-02-17 Thread JesterXL
Gotta go for the virus, buddy, ya' can't band-aid it up.  That guilt you're 
feeling is good.  Use that frustration to fuel your desire to solve the 
problem.  While you should be commended for finding a solution, it's still 
just a cover up for the real issue.

Post your getInstance method if you can't post the whole class, maybe that 
will help.

- Original Message - 
From: "Manuel Saint-Victor" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" 
Sent: Saturday, February 18, 2006 1:16 AM
Subject: [Flashcoders] When singletons go bad


In my app I have a Singleton that's composed of and manages a video
component.  In theory- anyone calling the getInstance should be getting that
same class and therefore subsequent references to its public properties
should be calling the same instanceright?

Problem is my getInstances() were not able to control things such as
Netstream in that class.  Is there some weirdness in having certain aspects
be static properties?  I ended up finally just pinning them to a namespace
on a static class (I'll call the class MJ for now)
like this

MJ.videoManager and MJ.stateObject   it works and I guess it's better than
_global(flame off... I know we've had this discussion already) but feels to
me that I've negated the benefit of the Singleton if I'm pinning my
singleton to the MJ static object and then just going there to find it as
other classes need it.
Don't get me wrong -it's working and we're happy- but a part of me feels
like I took this great pattern used it and then bastardized it.  When i try
to have other parts of the movie use getInstance to create a reference
variable and call methods on it i don't get results.

I can't really post code or give a whole bunch of details at this point so
I'm trying to describe it the best I can.


M
___
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] When singletons go bad

2006-02-17 Thread Manuel Saint-Victor
In my app I have a Singleton that's composed of and manages a video
component.  In theory- anyone calling the getInstance should be getting that
same class and therefore subsequent references to its public properties
should be calling the same instanceright?

Problem is my getInstances() were not able to control things such as
Netstream in that class.  Is there some weirdness in having certain aspects
be static properties?  I ended up finally just pinning them to a namespace
on a static class (I'll call the class MJ for now)
like this

MJ.videoManager and MJ.stateObject   it works and I guess it's better than
_global(flame off... I know we've had this discussion already) but feels to
me that I've negated the benefit of the Singleton if I'm pinning my
singleton to the MJ static object and then just going there to find it as
other classes need it.
Don't get me wrong -it's working and we're happy- but a part of me feels
like I took this great pattern used it and then bastardized it.  When i try
to have other parts of the movie use getInstance to create a reference
variable and call methods on it i don't get results.

I can't really post code or give a whole bunch of details at this point so
I'm trying to describe it the best I can.


M
___
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