6 Replies Latest reply on Jul 18, 2009 4:37 PM by paul.williams

    calling a function from a custom component

    MixMastaJames Level 1

      I got source files from another company that did a flex project for us before I started working here.  They have custom compenents (mxml files) that they are currently calling public functions in, but when I add a new public function to the mxml component, it won't allow me to call that function.  It tells me it can't access a property of a method of a null object reference... but it still calls the function that was there before I started working with the file..

       

      I cleaned the project, and did a "build all" but can't figure out why it won't allow me to create new public functions to call.... can anyone tell me why?

        • 1. Re: calling a function from a custom component
          MixMastaJames Level 1

          This basically whats happening:

           

          from the main mxml file:

           

           

           

          _tempScreen = new Dashboard();

           

           

           

          if (updatesRequired) {

              _tempScreen.showUpdates();

          }

           

          that works fine... and calls this function in the Dashboard.mxml:

           

           

          public function showUpdates():void {

              updateButton.visible = true;

          }

           

          I added this to be able to hide and unhide panels in the Dashboard mxml:

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

          public function showDefaultSceen():void {

               partsLocater_panel.visible = false;

               partsLocater_panel.includeInLayout = false;

               techManuals_panel.visible = false;

               techManuals_panel.includeInLayout = false;

               repairStatusReport_panel.visible = false;

               repairStatusReport_panel.includeInLayout = false;

               dmcReports_panel.visible = false;

               dmcReports_panel.includeInLayout = false;

           

               information_panel.visible = true;

               information_panel.includeInLayout = true;

          }

           

          and just try to call that function:

           

          _tempScreen.showDefaultScreen();

           

          and it gives me this error:

           

          TypeError: Error #1009: Cannot access a property or method of a null object reference.
          at com.globallearningsystems.lst.components::Dashboard/showDefaultScreen()[...\_source\Flex\ src\com\globallearningsystems\lst\components\Dashboard.mxml:51]
          at .../loadDashboard()[X:\NGC_LST\_source\Flex\src\NGC_LST.mxml:450]
          at .../startUpdates()[X:\NGC_LST\_source\Flex\src\NGC_LST.mxml:69]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at flash.net::URLLoader/onComplete()

           

          but I can put showDefaultScreen();  in the init(); function in the Dashboard.mxml file and it works... but I need to be able to hide and unhide panels from the "shell" on this component..

           

          what am I doing wrong?

          • 2. Re: calling a function from a custom component
            Gregory Lafrance Level 6

            Please post simplified yet complete code that illustrates how you are calling the public methods, from where and to where.

            • 3. Re: calling a function from a custom component
              MixMastaJames Level 1

              ahhh just did, might have been while you were posting... and it was all formatted propertly until I posted, sorry I can't seem to get it formatted properply to read...

               

              think I just reformatted it properly.....

              • 4. Re: calling a function from a custom component
                Gregory Lafrance Level 6

                Perhaps you did not initialize partsLocater_panel or something with new(), because it may have been declared but not initialized.

                 

                If this post answers your question or helps, please mark it as such.

                • 5. Re: calling a function from a custom component
                  MixMastaJames Level 1

                  I have the partsLocator_panel in the mxml

                   

                  not sure what "new" is with that... first time working with custom components, but it looks like your just working with custom classes in AS3...

                   

                   

                   

                   

                   

                   

                   

                   

                  <mx:Panel

                   

                  width="100%" height="100%" layout="absolute" styleName="DashboardPanel" title="PARTS LOCATER" backgroundAlpha=".6" id="partsLocater_panel">

                   

                   

                  <mx:Image x="10" y="38" source="assets/icons/gear.png"/>

                   

                   

                  <mx:Image x="10" y="63" source="assets/icons/gear.png"/>

                   

                   

                  <mx:Image x="10" y="89" source="assets/icons/gear.png"/>

                   

                   

                  <mx:Label x="40" y="39" text="Block 30" width="227" styleName="DashboardText" click="openParts()"/>

                   

                   

                  <mx:Label x="40" y="63" text="Block 40" width="227" styleName="DashboardText" color="#9D9D9D"/>

                   

                   

                  <mx:Label x="40" y="88" text="Block 50" width="227" styleName="DashboardText" color="#9D9D9D"/>

                   

                   

                  </mx:Panel>

                  • 6. Re: calling a function from a custom component
                    paul.williams Level 4

                    The stack trace you posted indicates that your showDefaultScreen method

                    is being called, but it is throwing an exception on line 51 (of

                    Dashboard.mxml). Can you post this line? Have you tried using the debugger?