When using Apache Flex 4.11 (or 4.12) – and the Spark VideoDisplay component (based around OSMF)… you may encounter the following runtime error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
This happens when attempting to reference the videoObject element of a VideoDisplay component. For example, when attaching a camera:
Why does this work correctly in 4.10 and breaks in never versions of Apache Flex? As explained in this bug report, it is because of the newer version of OMSF which is distributed with Apache Flex 4.11 and higher. This is a bug which Adobe needs to resolve, as they are still in charge of OSMF. Unfortunately, it appears that they do not actually care… which makes no sense – with “premium video” being one of the use cases for Flash Player which they tout in what little marketing they have around the runtimes.
Anyhow – enough complaining… how to fix it?
We will grab an older version of OSMF from Apache Flex 4.10 via Apache Flex® SDK Installer and simply copy osmf.swc into our Apache Flex 4.12 SDK. In fact, you probably already have 4.10 on your system if you are just noticing this issue.
Navigate to your Apache Flex 4.10 SDK installation (C:\sdks\4.10.0\ in my case) and copy frameworks\libs\omsf.swc.
Now, navigate to your Apache Flex 4.12 (or 4.11 or whatever) SDK installation (C:\sdks\4.12.0\ in my case) and rename frameworks\libs\omsf.swc to something like frameworks\libs\omsf.new. Now simply paste in the older swc you previously copied from the 4.10 sdk. If you now compile your project against the newer SDK – everything should work just fine!
Note that this… isn’t a perfect solution. You’ll be using the older OSMF libraries within your project so keep that in mind.