macromedia flash actionscript scripting, php, remoting, webservices, c#, javascript
At my last post i have written about dynamic-method-calls
in C-Sharp.
At this look we take a five-minute look at the communication
between C-Sharp and Flash.

Download Example
How do we start:
1.) You need to add an shockwave-flash element to the toolbar in the designer
of Visual-Studio. Click right at the toolbar and than choose add Element and
activate Shockwave Flas Object in Com-Control-Register.
For more details go to the excellent articel by Mike Chambers:
http://www.markme.com/mesh/archives/002977.cfm
2.) We need to load the flash movie into our ActiveX-Control. Therefore
we can use axShockwave.LoadMovie(0, "absolutPathToFlash") method.
3.) We need to send something to our Flash-Movie. Therefore we can
use the axShockwave.SetVariable("VariableName", "Value") method.
4.) Inside Flash we have to receive any change of the Variable, so we
can use something like that:
/////////////////////////////////////////////////////////////////
// C-Sharp-Message-Broadcaster
/////////////////////////////////////////////////////////////////
_root.bcCSharpMessage = function (varName, oldVal, newVal)
{
arguments.callee.broadcastMessage("onCSharpMessage", newVal);
}
ASBroadcaster.initialize(_root.bcCSharpMessage);
_root.onLoad = function ()
{
this.CSharpMessage = null;
this.watch("CSharpMessage", this.bcCSharpMessage);
}
/////////////////////////////////////////////////////////////////
// Test
/////////////////////////////////////////////////////////////////
// Receive from C-Sharp
obj = new Object();
obj.onCSharpMessage = function (strMessage)
{
_root.flashoutput_txt.text += strMessage + "\n";
}
_root.bcCSharpMessage.addListener(obj);
5.) To send variables to C-Sharp, we can use:
// Send to C-Sharp
_root.buttonSend_mc.onRelease = function ()
{
fscommand("flashMessage", "Hi C-Sharp");
}
6.) To receive in C-Sharp we need code like that:
//
// Let's subscribe at the fsCommand-Delegate from the swf-ActiveX,
// well this looks horrible to remember but if you are using
// Visual-Studio you get the fastest Auto-Complete you have ever seen.
this.axShockwaveFlash1.FSCommand +=
new AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEventHandler(axShockwaveFlash1_FSCommand);
private void axShockwaveFlash1_FSCommand(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent e)
{
// We only want to react if we got our command
if (e.command == "flashMessage")
{
this.richTextBox1.AppendText(e.args + "\n");
}
}
7.) Ready...;-)
Posted by hOk at August 25, 2003 08:08 PM
Comments (21)
Ah, you might be able to help me out with my SharpFlash project. It's a third-party flash extender (like SWF Studio and ScreenWeaver) written in C#. I should have a sourceforge project set up for it in the very near future.. Let me know if you're interested.
Posted by darron at August 26, 2003 01:34 AM
hey hOK, thx for sharing this!
I haven´t had time yet to set up this thing... is there a way to go without VisualStudio?
anyway... thinking about it... watch is slow and sockets (Darron´s approach, right?) is not easy to do.
but how about getter/setter? I think that would solve some problems - performance and ease of use.
I´m not sure, if it´s possible to access AS objects from .NET like:
axShockwave.SetVariable("CSharpComm.command", "Value")
if that´s possible, it would be the perfect solution:
CSharpComm={
}
CSharpComm.reveiveCommand=function(c) {
...
}
CSharpComm.sendCommand=function(c) {
...
}
CSharpComm.addProperty("command",CSharpComm.reveiveCommand,CSharpComm.sendCommand);
if something like this works, you still have to find a way to pass arguments, but you could just add them to the command like:
CSharpComm={
}
CSharpComm.reveiveCommand=function(c) {
...
}
CSharpComm.sendCommand=function(c) {
...
}
axShockwave.SetVariable("CSharpComm.command", "trace,\"hello world!\"")
Posted by Florian Krüsch at August 26, 2003 12:21 PM
oop, looks like mozilla kills my linebreaks ;)
Posted by Florian Krüsch at August 26, 2003 12:23 PM
It is possible to do this without IDE too: there is an aximp.exe in the SDK, which is used to import ActiveX controls to WindowsForms apps. It can also generate C# source code for the wrapper. But developing WindowsForms apps without an IDE can be painful. VS .NET is powerful, there are free alternatives, such as SharpDevelop or Borland's C# Builder - developer edition.
Posted by Ahmet Zorlu at August 26, 2003 03:56 PM
@darron:
Sounds interresting, painfully i have no
time for fun-projects.
I must say that i would like to see an other
approach which should solve the overhead for
embedding Flash-Elements in C#-Applications.
The target would be that you can design Flash-
Elements, that you can drag-and-drop in the
Visual-Studio-Designer like the other Controls.
The best thing were, if an C#-Class for Flash-
Elements were generated as proxy between the
Flash-Class and our C#-Application.
So Designer could build the Interface in Flash,
Flash-Programmer can write the AS-Interface,
and C#-Programmers can use the Api in C# because
a C#-Class was automgically generated. Yeah cool,
is'nt it?
@florian:
Looks good, in development we need to interpret
methods and property-settings dynamicly.
By the way, does anybody know how we can see
the commandline-command that Visual-Studio use
for the compiling the current project?
regards, Holger
Posted by hOk at August 26, 2003 05:24 PM
Hi, hab mir gerade deine Seite angekuckt. super.
Ich bin übrigens der Typ mit dem du dich am Samstag auf der "Karaoke-Party" unterhalten hast. Danke für deinen Forum und C#-Tip(hab schon ein bisserl mit SharpDevelop rumprobiert,cooooool). Ich finds ja auch wieder lustig das unter. "Scite|Flash: Mini-Tip - highlightning single-quoted strings" Mister Claus Wahlers, ein alter Kumpel von mir was gepostet. Jaja die welt ist klein.
cya steve
PS: Bist du an einem online-Debug-Tool interessiert das ich gebastel hab (wahrscheinlich ist dir eh sowas schon längst eingefallen)
Posted by steve at September 8, 2003 04:40 PM
Hehe, die Welt ist halt doch klein..;-)
Posted by hOk at September 9, 2003 06:50 PM
I really have not looked at C# much but rather use Delphi. I have created a few examples including one that connects to a database and send the results to the Flash within the window.
I am looking at creating full on applications that use Flash as a UI and Delphi as the underlying architecture.
Posted by Simon Barber at September 30, 2003 08:21 PM
Anyone know if there is a way to capture drag/drop onto flash control on C# form?
Posted by John at November 13, 2003 04:38 PM
Hi, I was wondering how I could implement playing a swf on a OpenGL texture?
Laura
Posted by Laura at January 16, 2004 04:08 AM
I have no idea for doing that..:-(
Posted by hOk at January 16, 2004 11:21 AM
Has anyone else had experiece of when using this method to detect variables changing value...that MovieClipLoader(); does not work ????
Much annoying bizarre-nes
-Fraser
Posted by Fraser at January 25, 2004 01:38 AM
Hi, I have found this article awesome...
We have been using Flash hosted in a C# win app for a few months now, but occasionally we get an exception from the Flash saying NullReference exception... Listed below...
It basically popped up an alert window with this error from Flash...
Do you have any ideas why this has happened??
Any Help would be much appreciated,
Regards,
Mark
-------------------------------------------------
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.AxHost.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Posted by Mark at March 16, 2004 03:52 PM
Mmmh,
maybe it has to do with the loading-order
of the components. You could look for a
swf-loaded-callback and use it as trigger
for your method-calls.
regards, Holger
Posted by hOk at March 16, 2004 05:16 PM
I'm getting kinda desperate, trying to solve a problem I'm having. I have a flash animation embedded in a C# app, and it works great. It doesn't need to send any variables to the C# app, because it's not interactive. It's just a quick little animation that works sort of like a splash screen. I didn't write it myself, and I really don't want to edit the code of it if I don't have to.
What I want to do is start a timer as soon as the animtaion is done playing. Basically, a few seconds after the movie finishes, the program will close that window, and bring up the main window for the program. But how can I tell if the movie is done? Is there an event I can register a handler for? Have you ever run into this problem?
Posted by bigelow_r at March 22, 2004 09:10 PM
Hi,
you can look in the AxShockwaveFlashObjects-Class
for events, but i don't have something like that
in my mind.
Else, you could use fscommand inside the flash
movie, like the example above.
regards, Holger
Posted by hOk at March 23, 2004 04:42 PM
Hi,
this article was fantastic! Thanks a lot!! :) Have been looking all over for a way to do this. Just wanted to express my thankfullness... :)
Laila
Posted by Laila at March 24, 2004 01:09 PM
Hi
Has anyone managed to load the Flash component using SharpDevelop? I try "loading the assembly" but nothing happens?
I've inherited a C# app that loads Flash in it and need to do a minor change but, without Visual Studio I'm battling. We normally do Web Applications so this is a bit new.
Great article though - sounds so easy if I could just load the component ;O).
Thanks,
Regards, Alison
Posted by Alison at March 26, 2004 01:52 AM
Hi,
while integrating flash with a VB.NET form, i'm facing issues with transparency. I've set the 'wmode' parameter to 'transparent' but still the flash's canvas shows when i run the form.
I'm having the flash 7 player installed on my sytem. Could that be an issue?
All help appreciated. Thanks in Advance.
Cheers,
FF
Posted by Frank at April 3, 2004 07:56 AM
Need Help
The same issue here:
...Wmode = "transparent" do not work in .NET
Thanks in Advance
>Miroslav
Posted by Miroslav Christov at April 12, 2004 11:48 PM
Does anyone know of a way to programatically add to a flash movie that is embedded in a .NET app? For example, is there a way to draw a textbox on a flash movie using the "Shockwave Flash Object" ActiveX component?
Thanks for any suggestions
Posted by td at May 10, 2004 06:14 PM
|
You can use <code>code that should be highlightned</code> to highlight code! Optionally you can use the attribut language="php|perl|java" within the code tag, otherwise actionscript-highlightning will be used. |
