# Trying to understand this code

**URL:** <https://forum.kirupa.com/t/trying-to-understand-this-code/276066>\
**Category:** Uncategorized\
**Created:** [November 21, 2008, 10:49pm UTC](https://forum.kirupa.com/t/trying-to-understand-this-code/276066 "2008-11-21T22:49:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![riveroaks](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@riveroaks](https://forum.kirupa.com/u/riveroaks)\
**Post date:** [November 21, 2008, 10:49pm UTC](https://forum.kirupa.com/t/trying-to-understand-this-code/276066/1 "2008-11-21T22:49:11Z")

</div>

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](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

```auto

    ....
    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

```auto
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
