3 Replies Latest reply on Feb 4, 2009 6:04 PM by levancho

    Null Object Reference Error When Passing Variable Back from TitleWindow to the Main Application?

    alice_data Level 1
      Hi,

      This seem like a weird problem, but I have have a scenario here where I am supposed to ask for the user's prompt to enter some information into a form and have that passed back to the main application. However, I keep on getting this error saying:

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

      I have set up the variable returnName.text in the appropriate "state" that I would like to display, but the line that tells me I have the error is scenarioName.text = scenario_name.text, which is in the child application. Since I am not making any changes the actual text, why am I getting this error?

      Attached is the code of the titleWindow and I have also provided what worked before, but I could not pass that back to the main application.

      Thanks for your help.
        • 1. Re: Null Object Reference Error When Passing Variable Back from TitleWindow to the Main Application?
          levancho Level 3
          from looking at the surface, I don't see you instantiating scenarioName
          so its null reference variable until you do scenarioName = new Text().
          it will generate that error
          • 2. Re: Null Object Reference Error When Passing Variable Back from TitleWindow to the Main Application?
            Level 7

            "alice_data" <webforumsuser@macromedia.com> wrote in message
            news:gmchqc$jv0$1@forums.macromedia.com...
            > Hi,
            >
            > This seem like a weird problem, but I have have a scenario here where I
            > am
            > supposed to ask for the user's prompt to enter some information into a
            > form and
            > have that passed back to the main application. However, I keep on getting
            > this
            > error saying:
            >
            > TypeError: Error #1009: Cannot access a property or method of a null
            > object
            > reference.
            >
            > I have set up the variable returnName.text in the appropriate "state" that
            > I
            > would like to display, but the line that tells me I have the error is
            > scenarioName.text = scenario_name.text, which is in the child application.
            > Since I am not making any changes the actual text, why am I getting this
            > error?
            >
            > Attached is the code of the titleWindow and I have also provided what
            > worked
            > before, but I could not pass that back to the main application.

            You're already using data binding, so you probably don't need to explicitly
            set the text there. I'm not exactly sure why you're getting that
            error...I'd need to play with it.

            The reason it's not passing back to Main is the thing that we've talked
            about before...when you launch a somewhat independent process, you CANNOT
            expect that you'll be able to retrieve the result of that process in the
            very next line. That next line will execute before the user has time to
            even blink, much less enter anything.

            Think back to how you've handled this before, and generalize the old
            solution to this somewhat new situation. As a reminder, look at Q15 here
            http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf.

            HTH;

            Amy


            • 3. Re: Null Object Reference Error When Passing Variable Back from TitleWindow to the Main Application?
              levancho Level 3
              i have to say (and I am not big fan of states in flex and very rarely using it (if ever :))
              but I see that your returnedName is declared withing state definition, and as I recall object within state definiton are not created immediately, eitherway from what I see, by the time this line is run:
              scenario.scenarioName=returnedName; // in your main
              returnedName is definately null.
              you can trace it and see,
              otherwise you code works just fine if you take out
              <mx:Text id="returnedName" text="" width="100%" x="10" y="521"/>
              from states definition and
              and put it within application.

              Regards
              Levan.