Wednesday, November 2, 2011

Null Object Reference in Flex 4's CrossDomainRSLItem

I just upgraded my computer and re-installed Eclipse and Flash Builder 4.5. And I ran into a familiar error:


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::CrossDomainRSLItem()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\CrossDomainRSLItem.as:115]
at mx.core::FlexModuleFactory/getRSLInfo()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:493]
at mx.core::FlexModuleFactory/update()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:368]
at mx.core::FlexModuleFactory/moduleInitHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:709]

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::CrossDomainRSLItem()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\CrossDomainRSLItem.as:115]
at mx.core::FlexModuleFactory/getRSLInfo()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:493]
at mx.core::FlexModuleFactory/update()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:368]
at mx.core::FlexModuleFactory/moduleCompleteHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:718]

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::CrossDomainRSLItem()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\CrossDomainRSLItem.as:115]
at mx.core::FlexModuleFactory/getRSLInfo()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:493]
at mx.core::FlexModuleFactory/update()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:368]
at mx.core::FlexModuleFactory/timerHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:732]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()


The last error just kept repeating infinitely.

This happened before so I'm just writing this down that I won't forget again what the fix was.

In my case, this happened because my Flex compiled SWF was loaded by another Flex compiled SWF. No issues there. The issue was: the my SWF (lets call it "baby SWF") was compiled in Flex SDK 4.5. The other SWF ("papa SWF") was compiled in Flex 4.1. 

The solution is to recompile baby SWF using SDK 4.1. This is a 4 step process:
  1. download the Flex 4.1 SDK
  2. add the Flex 4.1 SDK to the list of Eclipse SDK
  3. change my baby SWF's project settings to use Flex 4.1
  4. recompile and deploy

#1. I downloaded it here: http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4. I downloaded the "Adobe Flex SDK"

#2. In Eclipse preferences, under Flash Builder -> Installed Flex SDKs, click "Add". Browse to the Flex 4.1 SDK, and call it something sensible.

#3. In the baby SWF's project settings, under "Flex Compiler", select "Use a specific SDK" and select the 4.1 SDK.

#4. Happy developer...