I’m working on creating a liquid Flash layout and I found one tutorial that seems pretty helpful at http://www.adobe.com/devnet/flash/articles/liquid_gui_04.html
But can someone help me understand part of this code? My question about the code is down below the code
inside BodyUI Class
....
public static var _instance:BodyUI;
public var bg:Sprite;
private var _parent:Sprite;
public function BodyUI (p:Sprite)
{
_parent = p;
bg = new BodyBG ();
addChild (bg);
}
public static function getInstance (p:Sprite):BodyUI
{
if (_instance == null)
_instance = new BodyUI (p);
return _instance;
}....
then inside LiquidGUI_v3 Class
public function LiquidGUI_v3 ()
{
// Tell the player not to scale assets
stage.scaleMode = StageScaleMode.NO_SCALE;
// Tell the player to put coords 0,0 to the top left corner
stage.align = StageAlign.TOP_LEFT;
// Listen for resizing events
stage.addEventListener(Event.RESIZE, onResize);
// Create and add the Header UI
_header = HeaderUI.getInstance (this);
addChild (_header);
// Create and add the Body UI
_body = BodyUI.getInstance (this);
addChild (_body);
_body.y = _header.height;
// Create and add the Footer UI
_footer = FooterUI.getInstance (this);
addChild (_footer);
// Size everything after creation to ensure the app is drawn
// properly the first time it is seen prior to any user-
// initiated resizing
onResize (null);
}
my question is: why is there a static variable called “_instance” in the BodyUI class? I see that in the LiquidGUI class the _body is actually retrieved by using the _instance variable in BodyUI…but why not just say
_body = new BodyUI()
instead of saying
_body = BodyUI.getInstance()?
I just don’t understand how it makes sense to have a static variable here…it seems to be short-circuiting the OOP principles, not extending them.
Thanks