2 Replies Latest reply on Dec 5, 2008 9:46 PM by Tarindel

    Weird error when calling AS function to switch state from embedded HTML page

    Tarindel Level 1
      Hey everyone,

      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:
      htmlDOMInitialize="htmlReg.htmlLoader.window.changeState = changeState;"

      Inside the plain handcoded HTML web page that's loaded, there's a button that looks like this:
      <button onClick="changeState('Welcome')">Back to Welcome</button>

      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 error:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at flash.html::HTMLLoader/onFocusOut()

      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 different way?

      Thanks in advance.