Infosys Microsoft Alliance and Solutions blog

« Webinar - Modernizing from Mainframes to Next-generation IT Systems | Main | Silverlight - CheckBox issue when in ListBox »

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://.


 

 

TrackBack

TrackBack URL for this entry:
http://www.infosysblogs.com/microsoft-mt/mt-tb.fcgi/246

Comments

Thanks Chandan. This is helpful

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

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)