0

I've created a custom component and declared a skin part:

[SkinPart (required="true")]
public var label:Label;

During component initialization I set label.text to 'foo':

protected function init():void {
    label.text = 'foo'; //This line fails silently
    bar();
}

The function gets called when label is null and weird things happen:

  1. label.text = 'foo'; fails silently: no Exceptions are thrown, the console view displays nothing.
  2. bar(); is never executed.

I expect the app to produce a fatal error and exit but it doesn't. Why does setting a property of a null reference fail silently?

I've read about silent data binding errors here but label.text = 'foo'; doesn't bind anything. SDK version is 4.6.

hidarikani
  • 1,121
  • 1
  • 11
  • 25
  • 1
    It shouldn't fail silently. This looks an awful lot like a swallowed data binding error. Are you certain there is no data binding involved somewhere higher up the chain? (Not just inside the component; probably a binding that causes this component to initialise). – RIAstar Apr 23 '12 at 14:24
  • Share more code! When does your init() event run? Are you sure it is executed? There are a lot of events dispatched during the component creation lifecycle; which one are you listening for to run init? Is your init code in the component class or the skin class? Are you aware of the partAdded() method? In the Spark architecture, that is the appropriate place to set initial values on properties. – JeffryHouser Apr 23 '12 at 15:18
  • Looks like this has nothing to do with skin parts so I've created a [new question](http://stackoverflow.com/questions/10293507/why-does-mxml-data-binding-swallow-typeerrors). I've included a simple example that reproduces the error. – hidarikani Apr 24 '12 at 07:42

0 Answers0