in

ASP.NET Weblogs

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.

Published Dec 29 2003, 11:18 AM by XMLEvangelist
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

Leave a Comment

(required)  
(optional)
(required)  
Add