Hosting Flash movie in a WPF project
Earlier this week, I was facing a situation where I had to host a Flash movie (.swf) in a WPF from. There are several postings on this matter on the web, but none of them give you all the necessary steps and tricks in one place. So I am listing the resources used and steps followed to bring it all in one place.
First, like mentioned in this posting, you should start a new WPF project, add a WinFormsHost to the window, and use that to host the Flash .ocx, which lives down in c:\windows\system32\macromed\flash.
Then, as mentioned in this posting, it is necessary to run AxImp.exe from the .net sdk on the Flash ocx to generate following files.
AxShockwaveFlashObjects.dll
AxShockwaveFlashObjects.pdb
ShockwaveFlashObjects.dll
AxShockwaveFlashObjects.cs
In Visual Studio, add the references to the AxShockwaveFlashObjects.dll and ShockwaveFlashObjects.dll generated by aximp
Add namespaces to the imports section
using AxShockwaveFlashObjects;
using ShockwaveFlashObjects;
And here is the code to display SWF
AxShockwaveFlash axShockwaveFlash = new AxShockwaveFlash();
axShockwaveFlash.Location = new System.Drawing.Point(50, 50);
this.Controls.Add (axShockwaveFlash);
this.Show(); // Avoids InvalidActiveXStateException.
axShockwaveFlash.Movie = “D:\\test.swf”;
//* it is important to set Size after specifying Movie property
//* if Size is specified before, it is ignored
axShockwaveFlash.Size = new System.Drawing.Size(20, 20);
axShockwaveFlash.Play();
One tricky part about specifying the path for the movie file is that the path format has to match what the flash control wants. For the movie to work, the path had to be
absolute, the slashes had to be back slashes and the path had to start
with file://.

Comments
Thanks Chandan. This is helpful
Posted by: Atul Gupta | July 2, 2008 09:15 AM
What do you mean when you say use WinFormsHost to host flash.ocx. As I have been able to run the swf and can hear the audio in swf file but it's not visible.
Please let me know if there is any quick fix.
Thanks,
Anjali
Posted by: Anjali Batra | September 4, 2008 01:06 PM