Todays blog is about using the Flash ActiveX Object in a windows forms application.
I know that this is a very old topic to cover, but I found myself recently having to make changes to an old system that I wrote for a client back in 2007 when Flash was still the cool kid on the block.
The system was originally written in Flash and was used to play flash files based on some business rules. I later on rewritten the player in .Net for better compatibility with the rest of the system and to make the database communication easier.
When I started with the player I needed to find an easy way to control flash files within a windows forms application. After searching around the internet I came across a few libraries that helps with this, but they were all too expensive, and decided to use the flash object directly, the only problem was that there is little to no documentation around it.
I decided to write this blog entry with the hope that I can help someone who still needs to do that on old systems, if you aren’t using HTML5.
To get started with the Flash object, first you have to add the reference to your project, and to your toolbox in visual studio:
After you have added the Flash object to your toolbox, you can drag it onto your form, visual studio will include all the necessary references in your project.
For my project I have only used one event from the flash object to communicate back to .Net, and that is the FlashCall, which is the easiest way for a flash file to call back to the hosting application.
When you receive a callback on this event, remember to use threading or a timer if you need to make any changes to flash, such as load a new file, because you cannot update any properties so long as you are in the callback method.
In order to play a flash file, you only need to call it using the Movie property:
axShockwaveFlash1.Movie = file://C://File.swf
In windows 8 I have noticed that you also need to focus the control when loading a new movie, otherwise it doesn’t render.
In order to pause the movie, you can call Stop(); or Play(); to start it again.
And that is the basics you need to get started when you need to play flash files in your windows forms application. If you are like me and have moved on, then you will either be using HTML5, WPF or one of the newer platforms for animation within an application.