title: ActionScript: making a variable `[Bindable]` causes crashes
body: <p>I have this singleton that I'm using as a wrapper for global variables and constants, but as soon as I make some <code>[Bindable]</code> I get a crash on start up w/a bunch of red text in my console.</p>
  
  <pre>TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at BrandGlobals$/get COLOUR_EVERYTHING_BACKGROUND()[C:\MyProject\src\BrandGlobals.as:14]
      at BrandGlobals$cinit()
      at global$init()[C:\MyProject\src\BrandGlobals.as:2]
      at _mainWatcherSetupUtil/setup()
      at main/initialize()[C:\MyProject\src\main.mxml:0]
      at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2131]
      at mx.managers::SystemManager/initializeTopLevelWindow()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3400]
      at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3223]
      at mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3069]</pre>
  
  <p>BrandGlobals:</p>
  
  <pre><code>package {
  public final class BrandGlobals {
      [Bindable]public static var COLOUR_EVERYTHING_BACKGROUND:uint = 0xE010FF;
  </code></pre>
  
  <p>If I remove that <code>[Bindable]</code> and turn <code>var</code> to <code>const</code> there's no problem (except the obvious problem of not being able to set the variable outside of this file) but this doesn't work. Also, making the whole class <code>[Bindable]</code> instead of this one didn't work. When I hover my mouse over the <code>COLOUR_EVERYTHING_BACKGROUND</code> definition, it says "&lt;exception thrown by getter&gt;". 'Don't know what to think about that.</p>
  
  <p>I might have guessed it was because it has no package, but I'm using another similar singleton which has <code>[Bindable]</code> variables and seems to work fine.</p>
  
  <p>I never did get that <code>[Bindable]</code> twaddle.</p>
  
  <p>I'm using the Flex 3.5 SDK.</p>
  
  <p>I tried Brian's suggestion below, but it gave me pretty much the same error. I even tried:</p>
  
  <pre><code>{
      _COLOUR_EVERYTHING_BACKGROUND = 0xE010FF;
      trace("Var set."); //Breakpoint here
      bLoadedFerCryinOutLoud = true;
  }
  
  [Bindable]private static var _COLOUR_EVERYTHING_BACKGROUND:uint;
  private static var bLoadedFerCryinOutLoud:Boolean = false;
  
  public static function get COLOUR_EVERYTHING_BACKGROUND():uint {
      trace("Returning EVERYTHING background");
      if (bLoadedFerCryinOutLoud) 
          return _COLOUR_EVERYTHING_BACKGROUND;
      else return 0xFFFFFF;
  }
  </code></pre>
  
  <p>What's more, if I put a breakpoint at that <code>trace("Var set.");</code>, Flash Builder complains that a break is not possible, because there is no executable code there.</p>
  
  <p>I also noticed that in that call stack that I'm shown when this crash happens during a <code>set</code> and it seems to be the one that sets <code>_COLOUR_EVERYTHING_BACKGROUND</code>. But the only place where it is set is:</p>
  
  <pre><code>public static function SetBackground(oApp:UBIApplication):void {
      _COLOUR_EVERYTHING_BACKGROUND = oApp.nBackgroundColour;
  }
  </code></pre>
  
  <p>and breakpoints indicate that this is never called.</p>