5 Replies Latest reply on Sep 15, 2007 3:18 PM by Senor_Roberto

    Error 1009 on state change

    John R Nyquist
      I'm getting the following error when I do a state change:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at mx.states::RemoveChild/apply()
      at mx.core::UIComponent/::applyState()
      at mx.core::UIComponent/::commitCurrentState()
      at mx.core::UIComponent/setCurrentState()
      at mx.core::UIComponent/set currentState()
      at app::AppBase/app:AppBase::hideQ()
      at Main/___Box1_click()

      All the state is doing is:
      <mx:RemoveChild target="{questionsBox}"/>

      I'm using the code-behind approach where the MXML app is extending an AS3 class which extends from Application. The mx.states at the top of the stacktrace might be a clue. When I switched to the code-behind approach, I had to change the <mx:states> tag to <app:states> where "app" is the namespace for my Application subclass.

      Any suggestions would be appreciated.

      Regards,
      John
        • 1. Re: Error 1009 on state change
          Senor_Roberto
          You might need to take a look at the creationPolicy of the states.
          By default it's auto, so questionsBox may not be created yet when you're trying to remove it. Try changing creationPolicy to 'all'.

          If that doesn't work, can you post more MXML, including the states definition.

          Cheers
          • 2. Re: Error 1009 on state change
            levancho Level 3
            FYI using "creationPolicy =all" allover your application to resolve 1009 errors is also not very good Idea, there is the reason why creationPolicy by default is set to auto,if there is any possible way to avoid "creationPlicy =all", you should do so.

            • 3. Re: Error 1009 on state change
              John R Nyquist Level 1
              The questionsBox is created and in the display list at the time of attempting its removal. Here is an example of the MXML (just a snippet). Note that I had to change the states tag to support the code-behind:

              <?xml version="1.0"?>
              <app:AppBase xmlns:app="app.*" xmlns:mx=" http://www.adobe.com/2006/mxml" layout="horizontal" backgroundColor="0xFFFFFF" creationComplete="loadToc(event)" >
              <app:states>
              <mx:State name="QuestionsHide">
              <mx:RemoveChild target="{questionsBox}"/>
              </mx:State>

              I'll look at creationPolicy as I am not familiar with it. Any other suggestions are appreciated.

              Regards,
              John
              • 4. Re: Error 1009 on state change
                John R Nyquist Level 1
                For now, I've backed out of the code-behind approach until I can find out more why it causes problems with states. If anyone knows, please reply to this thread.
                • 5. Error 1009 on state change
                  Senor_Roberto Level 1
                  quote:

                  Originally posted by: levancho
                  FYI using "creationPolicy =all" allover your application to resolve 1009 errors is also not very good Idea, there is the reason why creationPolicy by default is set to auto,if there is any possible way to avoid "creationPlicy =all", you should do so.


                  Do you have more information about this? is it because of performance?

                  As far as I know the only hit you take using creationPolicy="all" is that the initialisation may take longer, since the children are being created upfront as opposed to dynamically, which is to be expected. I find this trade off entirely acceptable considering how much cleaner it can make the code when using custom components with view states or tabs, which is quite often.

                  Cheers