Embedding Flash in a Windows Forms .NET app
Mark G. Patterson asked:
"What's the best way to embed flash animations in .NET Windows Forms apps?"
Well, here's how I do it...
- First you want to add the "Flash" control to the Toolbox:
- Right-click on the Toolbox, choose "Add/Remove items..."
- Select the "COM Components" tab
- Scroll down to "Shockwave Flash Object" and make sure it's ticked
- Click OK
- Drag the "Shockwave Flash Object" from the toolbox onto the Form (just like any other control)
- Righ-click on the new object and select "Properties" to show the custom properties panel
Some things to keep in mind...
- You probably don't want to hard-code the URL for the move in the properties dialog, so try setting the "Movie" property to something like
Application.StartupPath + "\\MyMovie.swf"
- If you want to talk to the Flash movie from C# (or VB.NET or whatever) then you need to use the "SetVariable" method
- If you want to talk to the host Windows Forms app from Flash, use FSCommand... you'll need to add an event handler in your Windows Forms app
- Debugging is a real pain, if someone out there knows of a nice way to debug this combo, please let me know!
For communication, I prefer to use XML, as I can have any simple/complex data I like going back and forth. The C# to Flash communication is done via a Queue, Flash tells the C# host when it's ready for another message by using a FSCommand, at which point C# sends the next message on the queue. When a new message is added to the Queue, it checks if Flash is ready and if so sends it straight away, otherwise it's added to the queue ready for the next "I'm ready" command from Flash.
I can post some sample code if needed, but I'm sure most of you get the idea.