原先Winform只需要在Toolbox中choose加入Shockwave Flash Object即可,可到了WPF则变得有些麻烦,需要通过Winform来做跳板,具体如下:
1. 通过原先Winfrom的引入方式,将Flash控件拖入Winform中,VS会自动生成下面2个dll:

  • AxInterop.ShockwaveFlashObjects.dll
  • Interop.ShockwaveFlashObjects.dll

2. 将这两个dll copy到wpf的project中,在project新建2个目录分别是Lib和Runtime,将Interop…dll放入Lib,Ax…dll放入Runtime,在project编写Post Build Event,如下:
copy “$(ProjectDir)Runtime\*.dll” “$(TargetDir)”
将AxInterop.ShockwaveFlashObjects.dll在build后copy到最终exe生成的目录,因为运行exe需要它。

3. 在wpf project中add reference:

  • AxInterop.ShockwaveFlashObjects.dll
  • Interop.ShockwaveFlashObjects.dll
  • System.Windows.Forms
  • WindowsFormsIntegration

4. 开始编写放入flash的代码:

private void Window_Loaded(object sender, RoutedEventArgs e) {
	System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
	flash = new AxShockwaveFlashObjects.AxShockwaveFlash();
	flash.FSCommand += new AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEventHandler(flash_FSCommand);
	host.Child = flash;
	this.Stage.Children.Add(host);

	flash.Movie = @"c:\users\nonocast\desktop\hello.swf";
	flash.Play();
	flash.BackgroundColor = 0x000000;
	flash.SetVariable("testValue", "Hello World");
}

private void flash_FSCommand(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent e) {
	string cmd = e.command.ToString();
	MessageBox.Show(cmd);
}

private AxShockwaveFlashObjects.AxShockwaveFlash flash;

以Flash8 AS2为例(:(我也没办法),可以通过FsCommand事件接收flash中fscommand的调用,反之可以通过SetVariable给flash ’send message’.

5. 上面说到的Flash很简单,在第一帧中放入一个Label,然后F9编写’动作’,如下:

var testValue:String = "";
 watchCallback = function (id, oldval, newval):String {
	mylabel.text = newval;
	fscommand("GotIT");
	return newval;
 };
 _root.watch("testValue", watchCallback);

另外一种情况就是,直接采用动态文本,然后在’变量’中填上相应的变量名,然后直接就可以在.NET中Set,这个非常方便。
6. 参考Url:
Using the External API for Flash–JavaScript Communication
如何在 WPF 中嵌入 Flash (ActiveX)
7. 附上我的代码,有点乱糟糟,