Load Embedded Images into PaperVision3D BitmapFileMaterial Types
Sunday October 26, 2008
Sometimes you want to package things up nicely so that they don’t screw up if you’re files go missing from where you left them. Flash/Flex provide the ability to embed your images into the relevant SWF using the old [@Embed(source=‘some/image.jpg’)] metastatement.
Since the nice guys over Adobe still haven’t come round with the Idea of multiple constructors in AS3, there’s only one option when it comes to instantiating a class. This doesn’t play well when you can expect one of two alternative types as an argument.
The folks writing PaperVision3D recognised this, and created two classes to deal with it – BitmapFileMaterial (external file) and BitmapAssetMaterial (library symbol). Problem is, if you’ve got a load of code that you’d like to pilfer in the open source domain and it uses one particular type, you have to do a lot of find/replace/bugfixing in order to get the two to behave happily together.
Alternatively you can not stand for any of that shit and monkeypatch the functionality into the original type.
Patch
So here I present a modified version of BitmapFileMaterial.as, which should work in the releases 2.0a/GreatWhite, enabling you to pass in a class or URL as an option to the type constructor.