views:

63

answers:

2

In the following code the line after the if statement gets run even when "BITMAP" is null. Why is this?

public function get BitmapHeight ()
      {
        if (_bitmapHeight == 0 && BITMAP != null)
          _bitmapHeight = BITMAP.bitmapData.height;
        return _bitmapHeight;
      }
+4  A: 

That line of code should never be run if BITMAP is null.

Try this:

public function get BitmapHeight (){
    if (_bitmapHeight == 0 && BITMAP != null){
        trace("called with null");
        _bitmapHeight = BITMAP.bitmapData.height;
    }
    return _bitmapHeight;
}

Does 'called with null' ever get traced?

Cam
A: 

I'm taking a long shot here, but since you have no trace in place, I think it's possible that you're a judging whether the line after the codition is being executed or not by stepping into that line with the debugger...

If that's the case, it's possible that the source code you are seeing is not exactly the same code that was actually compiled into the swf. If you, for example, delete one line in that file (could be a blank line) once you've started debugging, the line numbers saved in the swf won't match the line numbers in the source code file you're seeing. This happens to me occasionally and gives me one of those WTF moments... until I realize I have done it again, so I just re-launch the debugging session.

Juan Pablo Califano