2 Replies Latest reply on Dec 30, 2010 9:58 AM by TrueSpace13

    Actionscript clas to MXML class error!


      Thank you for your help.  This problem has plagued me for hours.  I have an Actionscript class which I receive data from an SQLite database.  When I receive the data I call a method from my custom MXML s:BorderContainer class.  The MXML class is supposed to take the data and place markers on a Google Map.


           When I try to call any of my components (Buttons, Map, anything not written inside the fx:script of the MXML class it throws the one of two errors or alters nothing on the screen.  I understand this means I'm trying to play with the component before a certain process has completed (I'm a bit shaky at what point the MXML class needs to be in order for the components to be usable, if thats after initialization, creationComplete or if I need to use addChild or addElement somewhere per component for them to be usable).

           I've tried in the Actionscript class to create a new instance of the MXML class then call the method.  Inside the MXML class when I try to access a button component it throws the Error #1009: Cannot access a property or method of a null object reference.  Inside Actionscript after the new instance I used the .initialize() call to try and fix this and although it seemed to stop the null error, then I noticed it would do one of two things, it would either throw an Object not initialized error with some playing around (addElement calls, creationComplete call) or it simply would not display anything on screen.  If the code all worked I made sure it had made it to the method of the MXML class just fine and all the code had been used, however, no changes or new creations were shown on screen.


           I placed some simple code below to give a better visual of what I'm describing.  Any and all help is appreciated and thanks again.

      // The Actionscript class is named ConnectDatabase

      private var test2:MainContainer;


      test2 = new MainContainer();



      // After the data is received from the SQLite database I call the MXML class (MainContainer) function with the following:



      // Inside the MXML class named MainContainer

      - I've tried different addElement statements, but I'm open to any advice as I'm problem doing them wrong.

      - This is where I receive the nothing, the Error #1009: Cannot access a property or method of a null object reference, or the Object not Initialized errors.

        • 1. Re: Actionscript clas to MXML class error!
          Gregory Lafrance Level 6

          A couple of things come to mind.


          The first is where is the MXML component and when is it instantiated? If it is in the 2nd, 3rd, etc. view of a navigator container, and creationPolicy for the container is not set to "all" (and it should not be set to "all" in some cases), then this error can occur.


          If the MXML component is created based on the data returned, is it being created either in the data service result handler or at least in a method called from the result handler? Flex data calls are in general asynchronous, so you can't issue a data call send() and assume the data has been received and execute something after the send() that depends on the data.


          Not sure if this helps, but this is what comes to mind.


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

          Adobe Flex Development and Support Services

          • 2. Re: Actionscript class to MXML class error!
            TrueSpace13 Level 1

                 I appreciate the quick response.  The google map component is inside an mx:Accordion and is the first s:NavigatorContent which all is inside an outter mx:TabNavigator shell.  The MXML component (MainContainer) holds all of this and is first instantiated inside my main application class as the following:

            <local:MainContainer id="mainContent" top="0" height="100%"/>


                 The Main is of course called first, then the MainContainer which then the GoogleMap is the first inline of the tabs and accordions so it is called.  The instance of MainContainer is actually created in the constructor of my Actionscript class, but in the result handler I call the MainContainer function which is then suppose to use the ArrayCollection form a get function in the Actionscript class to help overlay markers on the map.


                 It seems since I call the new MainContainer() inside my Actionscript class it would make it the second or possibly third instance of MainContainer and it seems only the first instance which was called from the Main has the components available to play with.


                 The creationPolicy for MainContainer is not set to "all" and nor is it for the navigator container, but the map is the first component called.  Thanks again.