I'm developing an application that has 5 states in it. The
welcome state is set by default. I wrote a function called
changeState that looks like this:
internal function changeState(sState:String):void
currentState = sState;
Now, inside the registration state, there is an mx:HTML
component named htmlReg with the following attribute:
Inside the plain handcoded HTML web page that's loaded,
there's a button that looks like this:
<button onClick="changeState('Welcome')">Back to
The idea being, when the user clicks the HTML button, it
calls the AS function changeState('Welcome') and the user gets
taken back to the welcome screen.
The good news is that when I click this button, it works
fine, and I'm taken back to the welcome state.
The bad news is that when I then switch to another state
(using an mx:Button in the welcome state), I get the following
TypeError: Error #1009: Cannot access a property or method of
a null object reference.
I'm having trouble figuring out why this is happening, and
what to do about it.
Two additional data points:
1) If I add an mx:Button to the registration state with a
click="changeState('Welcome')" handler, it works as expected and I
don't get an error. I only get this error when clicking the HTML
button, which calls the same function in the same way.
2) If I move the mx:HTML component out of the registration
state and into the main application, I don't get this error any
more (and the HTML state change button still works as expected).
Anybody have any clues or ideas as to what might be
happening? Or ideas as to what I might try to collect more data
points? Or even workarounds to accomplish the same task in a
Probably what is happening is that when you change states,
the HTML control is removed from the stage. However, the HTMLLoader
(which is wrapped by mx:HTML) does seem to know that it has been
removed, and losing focus, it's internal handler for the focusOut
event access some property that requires it to be on the stage --
hence the null object reference.