3 Replies Latest reply on Feb 17, 2009 12:10 PM by DavidTheJavaProgramm

    Startup order

    DavidTheJavaProgramm
      My flex application is pulling data from a database that is then used in different UI components, like a bar graph, etc. I'm running into a problem, though, because the application is trying to render the bar graph before it pulls the data from the database. I'll try to put enough code in here to get the point across.

      First my mx:Application has the preinitialize property set to a method call loadData(). I also tried the initialize property but it gives me the same error. In loadData I'm calling the Remote Object methods that are correctly returning the data I need. But when I execute the application I'm getting an error:
      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at Dashboard/get barData()[C:\Documents and Settings\david.barron\My Documents\Flex Builder 3\Dashboard\src\Dashboard.mxml:305]

      The null object it is trying to reference is the ArrayCollection that contains the data that is coming from the database. When I debug I can see it is trying to use the ArrayCollection before the remote object method is executing.

      So, my question is, is there a way to call a remote object earlier in the startup process? From what I've seen in the docs it looks like preinitialize comes first, but apparently not. So how do I get around this?

      I will insert the code if that is needed.

      Thanks
        • 1. Re: Startup order
          kenped
          If you move the loadData() to creationComplete in the application tag,, do you still get this error?

          -Ken
          • 2. Re: Startup order
            DavidTheJavaProgramm Level 1
            Yes, I do. The only way to prevent the message is to have the Array that is throwing the error contain values initially, before making the call to the remote object. This works, sort of, but if I have to do that what's the point in getting the values out of the database to start with.
            In addition, if I do it that way the graph shows the initial values in the array, not the values retrieved from the database. I have to force the graph to redraw before it will show the retrieved values.

            I have to say, because of this and other things I've run into with Flex I am not impressed at all. It's clumsy, cumbersome and poorly thought out. At least with Java I can say "Do this before you do that," but I don't even have that much control with Flex.
            • 3. Re: Startup order
              DavidTheJavaProgramm Level 1
              I guess no one has any suggestion? This has become a significant
              problem and I need a solution if possible.