3 Replies Latest reply on Apr 20, 2011 4:53 AM by kurisu04

    (newbie) Error #1009 Cannot access a property or method of a null object reference.

    kurisu04

      I'm new to flex and am having a hard time of performing what should be a simple task: calling a custom component panel after logging in. The initial login screen appears, but after I hit login, I get the following error message

       

      "TypeError: Error #1009: Cannot access a property or method of a null object reference."

       

      In my main mxml file, I have the following code:

       

      <pre>

      <?xml version="1.0" encoding="utf-8"?>

      <containers:MainApp
                  xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                  xmlns:mx="library://ns.adobe.com/flex/mx"
                  xmlns:containers="containers.*"
                  xmlns:components="components.*"       
                  width="100%" height="100%"
                  creationComplete="init()" >

          <fx:Script>
              <![CDATA[
                  import com.utils.Login.security.*;
                  import com.utils.Configs;
                  import components.Panel1;

       

                  protected var components:Panel1;
               
                  private function init():void{
                      Configs.configure(buildDesktop);
                  }
                 
                  protected function onLoginSuccess(evt:LoginEvent):void{
                      loginScreen.visible = false;
                  }           
                 
                  private function buildDesktop():void {
                      components = new Panel1();
                      this.contentGroup.addChild(components);
                      loginScreen.init(Configs.begin);
                      loginScreen.addEventListener(LoginEvent.LOGIN_SUCESS, onLoginSuccess);
                  }
                
              ]]>
          </fx:Script>

          <containers:mainContent>   
                      <s:VGroup horizontalAlign="center" horizontalCenter="0">
                          <security:LoginScreen id="loginScreen" visible="true" />
                      </s:VGroup>
          </containers:mainContent>

      </containers:MainApp>

      </pre>

       

      Then in the component MXML file I have the following:

       

      <pre>

      <?xml version="1.0" encoding="utf-8"?>
      <s:Panel
          xmlns:fx="http://ns.adobe.com/msml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:mx="http://www.adobe.com/2006/mxml"
          xmlns:comp="components.*"
           allowClose="false">
         
          <mx:Script>
              <![CDATA[           
                  [Bindable]
                  public var text:String="Panel 1 appears!";  
              ]]>
          </mx:Script>
         
         
          <s:VGroup>
              <s:Label text="{text}" />
          </s:VGroup>
      </s:Panel>

      </pre>

       

      What am I doing wrong?

       

      Thanks.