View Single Post

#1
Bookmark and Share!
[AS3] Global Stage Singleton
Old 2008-03-19

I need help/opinion on something. I built a GlobalStage class which is a singleton that allows me to have a global stage variable. I have tried a few ways and maybe its due to my lack knowledge working with singletons. But is it possible to have a method inside the singleton to handle the stageAlign, scaleMode and the other stage properties?

At the bottom is a piece of my class, but I would like to have this singleton control all the stage properties in addition to allow me to have a global stage variable.

Anytime I trace "stage" inside the singleton it comes up null? I don't have to use a singleton but I felt it would be appropriate for what I was trying to accomplish.

ActionScript Code:
  1. public static function get instance():GlobalStage
  2. {
  3.     if( _instance == null )
  4.     {
  5.         constructorLocked = false;
  6.         _instance = new GlobalStage();
  7.         constructorLocked = true;
  8.     }
  9.    
  10.     return _instance;
  11. }
  12.  
  13. public function get stage():Stage
  14. {
  15.     return _stage;
  16. }
  17.  
  18. public function set stage( value:Stage ):void
  19. {
  20.     if( value != null )
  21.     {
  22.         _stage = value;
  23.     }
  24.     else
  25.     {
  26.         value = null;
  27.     }
  28.    
  29.     _stage = value;
  30. }
I'm going to eat your brain and gain your knowledge.
postbit arrow 6 comments | 2128 views postbit arrow Reply: with Quote   
Isocase
Registered User
Isocase is offline
seperator
Posts: 1,441
2006-11-03
Age: 28
Isocase's Avatar
seperator

Ultrashock Member Comments: