The problem i can see is tha in the singleton pattern constructor must be private.
May be triin with something like this : class com.shell.util.IntroAnimProxy { private static var _instance:IntroAnimProxy; public static function get instance():IntroAnimProxy { if( _instance == null ) _instance = new IntroAnimProxy(); return _instance; } private function IntroAnimProxy() { trace("IntroAnimProxy"); } } 2006/8/25, Adrian Park <[EMAIL PROTECTED]>:
Hey all! I'm using a class (AnimationProxy) based on the Singleton pattern to form a bridge between a timeline based intro animation (sigh) and the application objects (it's not strictly an intro because, when the intro is complete, the animation continues in the background whilst the rest of the site is rendered over the top). The animation is a standalone .swf loaded into the main .swf at runtime. It (the animation) has the AnimationProxy imported, registers a reference to itself with AnimationProxy and sends various events to AnimationProxy. The main application objects register as event listeners of AnimationProxy and respond to the events triggered by the animation. Well, that's how it's supposed to work! Thing is (and you may have seen the flaw already), I now discover that a unique instance of AnimationProxy is created by each of the intro and main .swfs! I'm fairly confident my implementation of Singleton is fine since it's the same implementation I've used several times. Two questions then... It kind of makes sense to me that each .swf maintains it's own object space (for want of a better term) and therefore it is expected that they would each end up with unique instances of AnimationProxy. Can someone give me a fuller explanation of why each .swf gets a unique instance? Can anyone suggest a better solution? I've included the code that constitutes the Singleton implemention below. Thanks Adrian class com.shell.util.IntroAnimProxy { // Singleton instance private static var _instance:IntroAnimProxy; public function IntroAnimProxy () {} public static function getInstance():IntroAnimProxy { if ( IntroAnimProxy._instance == undefined ) { IntroAnimProxy._instance = new IntroAnimProxy(); } return IntroAnimProxy._instance; } } _______________________________________________ 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
-- Andrés González Aragón Desarrollador Multimedia _______________________________________________ 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