Unless the singleton is in the main app's appdomain, each child has its
own singleton.

 

Putting the singleton in the main app or using a shared code module are
options.

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of tchredeemed
Sent: Thursday, May 29, 2008 12:37 PM
To: [email protected]
Subject: [flexcoders] Re: SingletonEnforced classes with modules

 

Hey alex,

I looked through the powerpoint and can't quite understand exactly what
a potential 
solution is.

Obviously both modules are creating their own instance, even though 
GCManager._instance is set the first time...

Grr!!

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> That's effectively the shared-class problem described in the modules
> presentation on my blog.
> 
> 
> 
> ________________________________
> 
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of tchredeemed
> Sent: Thursday, May 29, 2008 8:07 AM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] SingletonEnforced classes with modules
> 
> 
> 
> I have created a SingletonEnforced class to hold variables that might
> change, but will be 
> correct no matter where I access them.
> 
> public class GCManager {
> 
> private static var _instance:GCManager;
> 
> public var currentId:int;
> 
> public function GCManager( se:SingeltonEnforcer):void {
> return;
> }
> 
> public static function getInstance():GCManager {
> if(!GCManager._instance){
> GCManager._instance = new GCManager(new SingeltonEnforcer());
> }
> return GCManager._instance;
> }
> 
> }
> 
> class SingeltonEnforcer {
> public function SingeltonEnforcer():void {
> return;
> }
> }
> 
> If I am in a Module (call it Module A), and I set the variable
currentId
> to any number, then I 
> switch to a differnt module (call it Module B), and I try to get the
> variable currentId, it 
> returns 0. However, if I switch back to Module A, it is still the
number
> I set it to, and if I 
> then go back to Module B, it is still 0.
> 
> This would lead me to believe it is creating duplicates, or more then
1
> instance.
> 
> Any ideas? Anyone had a problem similar to this?
>

 

Reply via email to