7 Replies Latest reply on Feb 23, 2008 11:18 AM by Peter Farland

    works in Flex 2 - null object reference in Flex 3

    AlHolden Level 1
      I've reproduced from scratch a development project in my Flex 3 beta 3 plug in, creating each file within the Flex 3 environment. The only short cut I took was to copy the actual code from my eight Flex 2 project files (one main mxml, 4 custom mxml renderers and three included action script files) and paste them into the blank ones I created under the new Flex 3 project.
      When I run debug on the compiled Flex 3 swf; it throws an error that it didn't throw in Flex 2:
      Error #1009: Cannot access a property or method of a null object reference. I was getting the length of an Array which is populated as a result of a WebService result (same as I've always done. Did I mention it's the same code?).
      Furthermore, when I trap for this null then another whole swath of previously absent null references start to appear elsewhere, as though entire blocks of variables are no longer in the scope. Compilation issue?
      I don't want to post pages of source code to possibly duplicate a known issue/bug/blog/thread. Does this result look like something you've seen addressed before (ie "worked in Flex 2, broke in Flex 3"), and - if so - where?
      Update: No change in the code, but it worked once when I compiled it yesterday. Whoops, now it's broke again...
        • 1. works in Flex 2 - null object reference in Flex 3
          AlHolden Level 1
          OK, I suppose an example is in order.
          Behold, the app which works in Flex 2 but not in Flex 3
          The app throws an error here (line 23 in datastuff):
          var facilitiesForComboBox:Array = new Array(facilityDataProvider.length);
          because it did not place the results into the Array facilityDataProvider as it does in Flex 2.

          First, the mxml app, then the two AS files.
          • 2. Re: works in Flex 2 - null object reference in Flex 3
            Peter deHaan Level 4
            AlHolden,

            The webservice is throwing a fault for me (i'm guessing its the "foo" in the WSDL url).

            I'm guessing it's this line of code:
            facilityDataProvider = event.result as Array;

            I'm guessing the "event.result" can't be converted to an Array object and therefore is getting cast to null, therefore trying to access the length property of the array gives the error because you're trying to access a property (length) on a null object reference (facilityDataProvider).

            What happens if you try and do the following on line 20:
            [code]
            trace(event.result);
            [/code]

            Or,
            [code]
            import mx.utils.ObjectUtil;
            trace(ObjectUtil.toString(event.result));
            [/code]

            Peter
            • 3. Re: works in Flex 2 - null object reference in Flex 3
              AlHolden Level 1
              Thanks, Peter;
              I had to alter the url to obscure the name of the health care behemoth I work for. Any CF7 web service which returns a query containing the string columns NAMECLINIC and FACILITY should do. Email me [this.forumusername][at]akh[dot]com for the wsdl to the real service, if you'd like that. It's the same service used by our Flex 2 apps without issue.
              The trace revealed the same thing I see in the Variables window when the app crashes into Debug perspective (something I failed to mention earlier): a lovely ArrayCollection containing an ArrayList containing 209 records...
              • 4. Re: works in Flex 2 - null object reference in Flex 3
                Peter deHaan Level 4
                AlHolden,

                Is that similar to the output from Flex 2?

                Peter
                • 5. Re: works in Flex 2 - null object reference in Flex 3
                  AlHolden Level 1
                  No, they're not exactly the same (see below).
                  Calling the same web service; Flex 3 is generating a different result object than Flex 2, and therefore can/will not type the results as the Array my original app had come to expect. Is this by design?
                  A suggested code revision would help, but...

                  The question in my original post is still in play:
                  Where would I have gone to learn this? The release notes are simply a cut list of changes. Is there a resource which summarizes the types of errors one is likely to see when porting a Flex 2 app to Flex 3, along with the most-likely changes as causes? When CFMX was first released, there was a helpful checklist of tags and syntax to help you audit your CF5 for the upgrade. Has one of your gurus blogged something like this for FX3 and I just can't find it?
                  • 6. Re: works in Flex 2 - null object reference in Flex 3
                    Peter deHaan Level 4
                    AlHolden,

                    I don't know of such a document, but there may be something out there, or something may be written in the future.
                    As for the differences between Flex2/Array and Flex3/ArrayCollection, I've forwarded the question onto a couple engineers and will see what I can find out.

                    Thanks,
                    Peter
                    • 7. Re: works in Flex 2 - null object reference in Flex 3
                      Peter Farland Level 3
                      It could be that this scenario (and believe me there's not just a single scenario that could be involved for returning an Array from a WebService) in Flex 2 was a bug and the "makeObjectsBindable" setting may have been missed. Perhaps in Flex 3 this issue was fixed? Have you tried setting makeObjectsBindable explicitly to false?