10 Replies Latest reply on Aug 30, 2007 8:36 PM by SymTsb

    Null object reference

    Beatie3
      Hello, me again, I'm afraid. I'm using a nice little upload utility from Flepstudio. I've been reasonably successful in editing the code for my purposes, except I'm getting a null object reference error on one thing and I can't work out why, or really what that means. Could someone please explain that for me? I'm attaching the function that's causing the problem. The original class only uploaded an image into a loader. I'm trying to simultaneously load the same image into a Scrollpane as well. I would be most grateful for any assistance you could offer.

        • 1. Re: Null object reference
          Beatie3 Level 1
          Knock, knock.
          • 2. Re: Null object reference
            SymTsb Level 2
            I'm assuming that is is in reference to the loader.width and height calls. If this is a Loader object, to reference the width of said object, you need to actually target

            (loader.contentLoaderInfo.content as MovieClip).width

            The better way to do it would be to declare a variable to hold a reference to the loader's content like so...

            var ldrcontent:MovieClip = MovieClip( loader.contentLoaderInfo.content );
            trace(ldrcontent.width);
            trace(ldrcontent.height);
            • 3. Re: Null object reference
              Beatie3 Level 1
              Thank you for your response. Not really, though. The error wasn't generated until I added the sprite1 and scrollpane. The loader wasn't a problem. the original code calls the loader.contentLoaderInfo.content in the init function, which I'll attach. The only reference to null object reference in the documentation suggests it happens because the object hasn't been added to the display list with addChild(), but I added both Sprite1 and holder_sp using addChild, so I can't work out why the error is being called.

              Here's the other init function:

              • 4. Re: Null object reference
                SymTsb Level 2
                Can you provide the trackback from the Output panel for the error. It will provide me a great deal of information.
                • 5. Re: Null object reference
                  Beatie3 Level 1
                  Is this what you mean? This is everything from the output panel.

                  TypeError: Error #1009: Cannot access a property or method of a null object reference.
                  at Loading/::completato()

                  Thank you.
                  • 6. Re: Null object reference
                    SymTsb Level 2
                    comment out the two drawRect commands and see if the error goes away.
                    • 7. Re: Null object reference
                      Beatie3 Level 1
                      Ah, kewl! It changed at least so that's helpful. It's got something to do with the parent/child relationship:

                      TypeError: Error #2007: Parameter child must be non-null.
                      at flash.display::DisplayObjectContainer/addChild()
                      at Loading/::completato()
                      • 8. Re: Null object reference
                        Beatie3 Level 1
                        LOL, I found a post at Kirupa that went back to basic principles. I took its advice and separated declaration and instantiation of my variables and suddenly no more error message and my image loaded directly into the Scollpane, which was what I wanted all along. Of course its AS3, so there are no unmitigated victories. According to my trace it is still loading into the loader as well, but it's invisible!

                        I'm attaching the two relevant pieces of code:
                        • 9. Re: Null object reference
                          Beatie3 Level 1
                          Woo hoo!!! Thank you very much, SymTsb. I worked my way through it and I've now got the uploaded image loading into both the thumbnail loader and the ScrollPane. Very happy indeed!

                          Here's what I ended up with that obviously did the trick:

                          • 10. Re: Null object reference
                            SymTsb Level 2
                            You're welcome although you should pat yourself on the back. Job well done!