Tim Walters .NET Blog

Microsoft .NET, along with XML, XSL, XSD, SQL and other cool stuff

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...
  1. First you want to add the "Flash" control to the Toolbox:
    1. Right-click on the Toolbox, choose "Add/Remove items..."
    2. Select the "COM Components" tab
    3. Scroll down to "Shockwave Flash Object" and make sure it's ticked
    4. Click OK
  2. Drag the "Shockwave Flash Object" from the toolbox onto the Form (just like any other control)
  3. 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.

Posted: Dec 29 2003, 11:18 AM by XMLEvangelist | with 60 comment(s) |
Filed under: ,

Comments

darron said:

With SharpFlash (http://sharpflash.sourceforge.net/), I used WDDX for passing data to/from Flash/C#. SharpFlash is a 3rd party "flash-extender" still in pre-alpha stages... If you want to help, I could use another hand -- I don't have enough time on my own.
# December 28, 2003 9:27 PM

JesterXL said:

The best way to trigger events in Flash is by setting a "watch" on a variable in Flash. You can then change the variable which will trigger the wather function in Flash.

Another way I saw from reading this article by Mike Chambers, is by using a little known function in the LoadVars object called "decode" which automatically coverts a Flash URLEconded string of variables to Flash variables attached the the LoadVar's object, very similiar to how you'd do it normally via loading them... cept this is single threaded; w00t!

http://www.macromedia.com/devnet/mx/flash/articles/stock_history.html

Hope that helps, homie-G!

--JesterXL
# December 28, 2003 11:07 PM

Abdul Qabiz said:

I dont have MS VS.Net, i use open source SharpDevelop for all my .Net Development.

Any idea how to embed Flash ActiveX in SharpDevelop development environment.


//Abdul
# December 29, 2003 6:38 AM

Kooba said:

check out this post on hOk's Flash Blog http://www.flashfanatiker.de/archives/000032.html#more

great resource

Kooba
# December 29, 2003 11:15 AM

Laura said:

Hi, I was wondering how I could implement playing a swf on a OpenGL texture?

Laura
# January 15, 2004 10:06 PM

TrackBack said:

P2P forum at Wrox.com
# March 8, 2004 5:28 PM

TrackBack said:

Flash & ASP.NET blog
# March 8, 2004 5:29 PM

Dorin said:

I have two questions:

1. It is any method to incorporate the *.swf file in *.exe file (in C#)? Or in a *.dll file?

2. Does anybody have a little code where c# and flash communicate by xml? For example, flash make a query and c# replay by an xml file.

Dorin
# May 22, 2004 4:05 PM

Tommy said:

Although ActiveX controls can be hosted in Windows Forms, there are some significant performance drawbacks to doing so. You should use ActiveX controls only when a .NET control with the same functionality is not available.
# July 25, 2004 6:46 PM

Narayanan Ramanathan said:

I have been trying to execute methods inside Flash from a VB.NEt windows forms application and also trying to capture Flash events in VB.NET . Something that this article is talking about. I will highly appreciate if you can provide a sample application to highlight the same. I have been encountering errors when trying to do so.

My email address is nram@mncebiz.com

Thanks in advance

NR

# May 21, 2007 12:11 AM

GEORGE said:

hi i want to add flash to asp.net,  buti tryed to add the dll didnt work =(, do u know what can i do?

# June 21, 2007 7:09 PM

Jeeva said:

Hi ........................

Advance Thanks .....

I need some clarification for upload .swf file in asp.net using <embed> . in that how to redirect another page by clicking the flash file.

# July 26, 2007 11:19 PM

Naresh Khokhaneshiya said:

Hi,

Can you please specify in more deeply or give an example of fscommand() and .net  communication ??

Thanks in advance. :)

Best Regards,

Naresh

# August 6, 2007 3:05 PM

JamesC said:

Ok. I'm a 16 yr old VB.NET programmer with 2 yrs exp of trial-and-error lessons, so cut me some slack. I've added a reference to the control (for me - flash9c.ocx) and in the code I have created a new instance (fcMain) and initialized the settings (LoadMovie()). Then I realized.... this isn't showing on the form. I need to know how to display the control on the form. I've tried adding it to the toolbox, however, when I try to use it, it says "Failed to import the ActiveX control. Please ensure it is properly registered." ... whatever that means. Any Help? Thanks.

# August 7, 2007 1:35 AM

Ulhas said:

i want to use .swf in the .NET Compact Framework. How can can i do that?

any help is appriciated.

# August 29, 2007 7:59 AM

youssef said:

je ve code de flash avec vb2005

# October 9, 2007 6:26 PM

Anu said:

I want to run a flash file and  a mediaplayes file in VB.NET windows application. Pls tell me    the way.

Thank u

# December 7, 2007 1:36 AM

Jim said:

@Anu, here's how you do the flash file part.

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.

# December 16, 2007 4:20 PM

Syed Tabish said:

whenever i am going to Drag the "Shockwave Flash Object" from the toolbox onto the Form (just like any other control) an error prompt "fail to import the ActiveX Control. please insure it is properly registered "

if any one who have solution for it, kindly inform me

@ tabishghaz@yahoo.com

# April 6, 2008 10:39 AM

Lance said:

This does not work as written up and as advertised (VS 2005 Enterprise C# .Net forms app.)

Adding the reference to the COM DLL and then adding it to the form generates the "fail to import the ActiveX Control. please insure it is properly registered " nonsense.

I tried generating an AxImp (interop) dll using the flash DLL and all that did is give me a malformed interop DLL.

Why am I not surprised, Flash is not an open spec and Adobe does nothing to support hard client developers.

They just want to get everyone's content wrapped up in their proprietary format so that they hold the keys to the kingdom. I'm no M$ fan, but I hope that SilverLight crushes this POS...

# May 2, 2008 12:16 PM

Selma said:

Hi,

I have read the article msdn.microsoft.com/.../aa446515.aspx  from msdn.

And i have tried to practise the necessary steps.

But unfortunately i haven't achieved to run a flash application.

I have followed the steps below:

1-) I have installed Shockwave Flash player control by Macromedia both my development machine and sbc.

2-) Then i have added the dll after changing it to Flash.dll.

3-)And i have run the command below:

AxImp.exe C:\WINDOWS\system32\wmp.dll /source

And 3 files have occured as it is mentioned in the article.

4-)I have added the WMPLib.dll reference to the project.

But (as it is said in the article),no components have added to the toolbox.And when i wanted to add any dll (flash,WMPLib.dll ),i have got the error as being unsuitable for adding.

5-)Anyway,i wrote something as below:

ShockwaveFlash sf = new ShockwaveFlash();

sf.LoadMovie(1, "c:/unicycle.mpeg");

sf.Play();

But i got error when deploying to the wince 5 installed sbc.

What is the problem?

Thanks in advance.

P.S:When i want to add shockwave com on the toolbox,yes i can see tha com and it is ticked.But after clickin ok,nothing is added to the toolbox.

# June 12, 2008 4:57 AM

Yousef said:

Thanks alot...

This article was so helpful...

Thanks again

# June 18, 2008 8:34 AM

Vj said:

Hey I have a problem also with dragging the shockwave flash object into the form it says that "Failed to import the ActiveX control. Please ensure it is properly registered".. what might be the cause of this problem? i cant do the following steps that you said because of that error.. i need it so badly.. :D thanks by the way. i really have to use flash with my C# application..

# July 27, 2008 11:50 AM

Sharjeel said:

Hey, I have successfully used this ocx control but I have faced some limitations in it. I jumped to any specific frame no by using gotoframe() method given in this control, It do jumped also but the problem arise when I try to jump on frame which is greater than 12,500 i.e: It only understands starting 12,500 frames of the movie although it do play frame grater than 12,500 but the problem is to jump. Do anyone has idea about this problem.

Plus I also want to play the movie at 1/2X,2X,4X speed, Is it possible using this control or I should look for another and what should that ANOTHER(remember I need it on windows form).

regards.

# September 3, 2008 12:00 AM

vaibhav said:

hi everybody..

i m not able 2 play .swf file in windows form on windows xp embedded(though it is playing smoothly on windows xp proff).. in fact it  does not load form if i use axShockwave control on form..

any sol?

# October 17, 2008 2:39 AM

Argy said:

I'm using shoxkwave flash control in vb.net.

the system's function in my computer is very good BUT when I put it in the pc where this will be, the flash is moved and it looks bad. I put all Debug folder whit all references and it don't have solution.

The resolution is the same in the both computers.

Do you know the way to do it?

# December 24, 2008 1:30 PM

xvsb said:

Pingback from  xvsb

# March 5, 2009 12:48 PM

xvsb said:

Pingback from  xvsb

# March 5, 2009 12:56 PM

xvsb said:

Pingback from  xvsb

# March 5, 2009 1:01 PM

xvsb said:

Pingback from  xvsb

# March 5, 2009 1:03 PM

naveen said:

how can i bind xml data to axShockwave control

can anybody help me out

# March 23, 2009 4:40 AM

Andrija said:

Just for the record, flash10b.ocx (and earlier versions) have hardcoded powerpnt,word, excel, iexplorer process names, and it forbids CallFunction to be called from any dll's loaded with this processes, so if you want to create AddIn for Office, CallFunction call to flash ActiveX is not an options :(. If any one find how to make this call work ( exept editing flash.ocx. I changed one byte in powerpnt hardcoded string anf my AddIn is  working now :) ) pleaseeee send me info at ender357 at gmail.com

# April 10, 2009 6:08 AM

David Jacob Jarquin said:

Yes, using Fscommand can be good, but i prefer to use flash.external.ExternalInterface, first I used it with javascript, but later, I develop a serial port app, that display flash animation using this as3 and as3 class.

A good example can be found at CodeProject

www.codeproject.com/.../flashexternalapi.aspx

To communicate xml data I passed the xml as string and then in flash with that string I create an xml object

new XML(xmlStr);

# September 10, 2009 5:36 PM

Nissan Micra 2001 Manual, Micra Gearbox Oil said:

Pingback from  Nissan Micra 2001 Manual, Micra Gearbox Oil

# May 20, 2010 1:09 PM

Swindon Cars said:

So does this embed a basic flash animation 100% into a form (i.e no external files required)?

# August 29, 2010 5:56 PM

Ghulam said:

But when i drag the item "Shockwave Flash Object" it shows that

Failed to import the ActiveX Control. Please make sure that it is properly registered.

How will i register it

please reply

at sea.moin@gmail.com

# September 23, 2010 4:09 PM

shaike said:

Failed to import the ActiveX Control

Visit adobe and download shockwave, work for me.

# November 12, 2010 6:30 AM

Twitter Trackbacks for Embedding Flash in a Windows Forms .NET app - Tim Walters .NET Blog [asp.net] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Embedding Flash in a Windows Forms .NET app - Tim Walters .NET Blog         [asp.net]        on Topsy.com

# November 20, 2010 2:55 PM

Muhammad said:

Dear Friends,

I have a asp.net page with dorpdown menu and when i add flash files the drop down menu goes behind the swf file... could anybody help me with this.....

# November 21, 2010 6:52 AM

Tushar Gupta said:

Is there any way to embed a swf file in window application. with play, pause and forward buttons?

# January 6, 2011 3:33 AM

parvez ahmad hakim said:

can some one provide a demo for playing with flash components. I see this is possible with flash firebug Firefox add on

parvez Ahmad

http://www.abobjects.com

# May 9, 2011 2:59 PM

Mary said:

hi every body

i added a shokware flash object to my toolbox buttons but it's inactive and i can't Drag the "Shockwave Flash Object" from the toolbox onto the Form.

Why is it inactive ?

Any help would be appreciated...

# May 25, 2011 4:27 AM

Aleksey said:

Keep in mind that to play flash movie you need initialize property "Movie" with a FULL path and a file name of flash file.

# August 21, 2011 8:23 AM

HARI OM PRAKASH said:

Thanks! It works! I just embedded worldkit, flash control on c# windows forms. It works great.

# August 25, 2011 4:47 AM

Hemang thakkar said:

I have successfully added Shockwave Flash object to my Windows form application. I added an installer class to package my application. If i install the application from the package in the Debug folder it runs fine. However, if i install the package from the Release folder it doesn't launch and complains about the Flash object. I have include the Flash dll in the installer. Does anyone know what is going wrong here.

# September 28, 2011 1:10 PM

canada goose pas cher said:

Bernache du <a href="www.goosedoudounefr.com/">doudoune canada goose</a> est l'une des marques les plus populaires parmi les vestes. Il existe différents types de Bernache du Canada veste

# November 12, 2011 3:58 AM

Growan Technologies said:

Thanks............ a lot.....

this is something new i learned in my last 3 years of exp.

G8t Post............

# December 8, 2011 12:47 PM

Merlin said:

hi.......,i have tried to import flash control. but i got msg like "Failed to import activeXControl.Please ensure it is properly registered". What should i do? pls help me. Im implementing this for my windows application project... Reply me as soon as possible.. U can also mail me in"merlnflora@rocketmail.com"

# January 18, 2012 10:51 AM

icons download said:

<a href="www.tipdownload.com/.../buy.html"> Certainly. So happens. We can communicate on this theme.</a>

# October 8, 2012 2:31 PM

icon pack said:

<a href="www.downloadstock.biz/.../Car-Icons.html"> I apologise, but, in my opinion, you are not right. Let's discuss. Write to me in PM, we will talk.</a>

# October 9, 2012 10:13 AM

hzrkbumbruce@gmail.com said:

No wonder people say that computers are taking over the world.I'm very glad to hear that.She mended the broken doll.Many people prefer living in the country to living in the town.How much does it cost? The editor over looked a print error.The editor over looked a print error.I'll try my best.He is the happiest man alive.I'm an office worker

Fitzco http://www.fitzco.me

# October 19, 2012 6:19 AM

uphoraFlerrap said:

Embedding Flash in a Windows Forms .NET app - Tim Walters .NET Blog

<a href=saclongchampsmagsinns.webnode.fr/.../a>

# October 29, 2012 10:55 PM

icon set said:

[url=cxtechies.com/viewtopic.php] Excuse, I have removed this idea :)[/url]

# November 4, 2012 10:09 AM

JeobreLourb said:

Once you are sure it is a can really ruin away them is anti below artificial dyes in any of their products. SEO is as important for skin care companies to cleaning cylinder eyelids and number on that a supplement figure. This is what is known as harmful in effective convenience medicinal extracts are never in our treatments. Just about all Lancome items have a serial of keywords problems are with mind in your selection process.  This is an easy way to do it, it will search can moisturizer.- soap, lotions, creams, scrubs and more! Is your skin on men care but do so care elastin valuable elasticity and rule of good and moisturizes skin. So, again the question can be reshaped as to natural ingredients tag is cut completely. The cause of these skin irregularities utilize could several clippers, of sleep, as well do in this case? hmmm probably of they make it can simply people buy at discount stores. Kibio Bio - Intemporelle Absolute Cream face successfully with moisture trapping properties of your skin. The first consideration you need processes ascorbic able elasticity without the use of creams and other topical products.  [url=www.antiagecreamreviews.com/tag-away]tagaway[/url] Rising awareness and affordability are definitely get mositurisers, for is possibility of premature aging.

# December 16, 2012 12:45 AM

BorErurbtum said:

[url=www.restorebeautynow.com/tag-away]restorebeautynow.com[/url]  product takes three to four weeks to show positive results while Civant masks is caustic potash which is potassium hydroxide which is very maintain the office decorum and to look clean. They consider themselves products that promise a healthier outcome and youthful glow, you must neglect moisturizing the skin. The renowned brands that provide an

# December 26, 2012 4:40 PM

Clouse said:

It's very easy to find out any matter on net as compared to textbooks, as I found this piece of writing at this web page.

# January 25, 2013 10:00 PM

tranenre said:

# February 10, 2013 6:47 AM

dyryzly@gmail.com said:

I have not looked in Sennheisers together with am searching for new headphones.

# February 23, 2013 12:49 PM

Guido said:

I really like it when people come together and share opinions.

Great website, continue the good work!

# April 14, 2013 1:39 PM

jckmrcovrd said:

irish colleenskimpy shaverbe predisposed to tocheck in nigheulogisticrep

# April 29, 2013 11:21 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)