How to Embed Flash Into Your 3D Application
The original source of this post is at the IMVU engineering blog. Subscribe now!
[I wrote this post last year when IMVU still used Flash for a significant portion of our UI. Even though we now embed Gecko, I believe embedding Flash is still valuable.]
Writing user interfaces is hard. Writing usable interfaces is harder. Yet, the design of your interface is your product.
Products are living entities. They always want to grow, adapting to their users as users adapt to them. In that light, why build your user interface in a static technology like C++ or Java? It won't be perfect the first time you build it, so prepare for change.
IMVU employs two technologies for rapidly iterating on and refining our client UIs: Flash and Gecko/HTML. Sure, integrating these technologies has a sizable up-front cost, but the iteration speed they provide easily pays for them. Rapid iteration has some obvious benefits:
- reduces development cost
- reduces time to market
and some less-obvious benefits:
- better product/market fit: when you can change your UI, you will.
- improved product quality: little details distinguish mediocre products from great products. make changing details cheap and your Pinto will become a Cadillac.
- improved morale: both engineers and designers love watching their creations appear on the screen right before them. it's why so many programmers create games!
I will show you how integrating Flash into a 3D application is easier than it sounds.
Should I use Adobe Flash or Scaleform GFx?
The two most common Flash implementations are Adobe's ActiveX control (which has a 97% installed base!) and Scaleform GFx.
Adobe's control has perfect compatibility with their tool chain (go figure!) but is closed-source and good luck getting help from Adobe.
Scaleform GFx is an alternate implementation of Flash designed to be embedded in 3D applications, but, last I checked, is not efficient on machines without GPUs. (Disclaimer: this information is two years old, so I encourage you to make your own evaluation.)
IMVU chose to embed Adobe's player.
Deploying the Flash Runtime
Assuming you're using Adobe's Flash player, how will you deploy their runtime? Well, given Flash's install base, you can get away with loading the Flash player already installed on the user's computer. If they don't have Flash, just require that they install it from your download page. Simple and easy.
Down the road, when Flash version incompatibilities and that last 5% of your possible market becomes important, you can request permission from Adobe to deploy the Flash player with your application.
Displaying SWFs
IMVU displays Flash in two contexts: traditional HWND windows and 2D overlays atop the 3D scene.
If you want to have something up and running in a day, buy f_in_box. Besides its awesome name, it's cheap, comes with source code, and the support forums are fantastic. It's a perfect way to bootstrap. After a weekend of playing with f_in_box, Dusty and I had a YouTube video playing in a texture on top of our 3D scene.
Once you run into f_in_box's limitations, you can use the IShockwaveFlash and IOleInPlaceObjectWindowless COM interfaces directly. See Igor Makarav's excellent tutorial and CFlashWnd class.
Rendering Flash as an HWND
For top-level UI elements use f_in_box or CFlashWnd directly. They're perfectly suited for this. Seriously, it's just a few lines of code. Look at their samples and go.
Rendering Flash as a 3D Overlay
Rendering Flash to a 3D window gets a bit tricky... Wait for Part 2 of this post!
Hi there, I really didn't know where else to ask this since the forums on IMVU basically state no one is helping with this.
On my old laptop, I can shop for music from the website and listen to the previews and play it in the 3d client.
On my new laptop which has Windows 8, and Vipre anti-virus, when I click the play buttons to preview the songs on the website, it just says in the bottom left corner : java scrips:stop(); Also while in the client, the place that would have the playlists remains back and with a spinning icon that never loads.
Am I part of the 5% with flash incompatibilities or could it be something else that I can fix?
Sorry to ask you about this but I'm desperate for some kind of answer and you seem to know your stuff.
Thanks for your time, Leilani