、新建一个C#WINDOW项目,给项目命名为FlashPlayerApp。 2、选择菜单中的“工具”--“自定义工具箱”,打开“自定义工具箱”窗口,在“COM 组件”中点击“浏览”键,然后选择““ShockwaveFlash Object”,将其拖到新建的Form1上. 3、再从工具箱中,向Form1设计窗口中添加一个mainmenu控件、一个 panel控件、一个 imagelist控件、在panel控件上,添加4个 button控件。 4、编辑主菜单,添加菜单项“打开”和“退出”等 5、在设计窗口中双击菜单“打开”,添加代码如下: private void menuItem2_Click(object sender, System.EventArgs e) { OpenFileDialog openFlashDlg = new OpenFileDialog (); openFlashDlg.Filter = "Flash 动画(*.swf)|*.swf"; if ((openFlashDlg.ShowDialog () == DialogResult.OK ) && (openFlashDlg.FileName != "")) { btnPlay.Enabled = true; MySWF.Movie = openFlashDlg.FileName ; this.Text = "Flash Player " + openFlashDlg.FileName; } } (请高手解释以上这部分程序) 6、在设计窗口中双击各功能按钮,添加控制FLASH播放的代码如下: private void btnPlay_Click(object sender, System.EventArgs e) { myPlay(); }
private void btnPause_Click(object sender, System.EventArgs e) { myPause(); }
private void btnBack_Click(object sender, System.EventArgs e) { for (int i=0;i<10;i++) { MySWF.Back (); } myPause(); }
private void btnForward_Click(object sender, System.EventArgs e) { for (int i=0;i<10;i++) { MySWF.Forward (); } myPause(); } 添加myplay()和mypause()函数代码如下: private bool bPlay = false; private void myPlay() { if ( bPlay = !bPlay) { MySWF.Play (); btnPlay.ImageIndex = 0; btnPause.Enabled = true; btnBack.Enabled = true; btnForward.Enabled = true; } else { MySWF.StopPlay (); btnPlay.ImageIndex = 1; btnPause.Enabled = false; btnBack.Enabled = false; btnForward.Enabled = false; } } private void myPause() { if (MySWF.Playing) { MySWF.Playing = false; btnPause.ImageIndex = 6; } else { MySWF.Playing = true; btnPause.ImageIndex = 5; } } 最后编译运行即可