AxShockwaveFlash的LoadMovie抛出System.AccessViolationException异常

时间:2014-07-04 09:38:50

标签: c# flash axshockwaveflash

尝试在C#和flash对象(swf)之间进行通信时,我遇到以下异常。我尝试阻止Flash64_13_0_0_214.ocx生成2个程序集AxShockwaveFlash.dll和ShockwaveFlashObject.dll,然后我在一个控制台应用程序中测试我的代码。我的代码通常是这样的:

AxShockwaveFlash player = new AxShockwaveFlash();
player.CreateControl();
player.WMode = "transparent";
player.AllowScriptAccess = "sameDomain";
player.Loop = false;
player.LoadMovie(0, @"encrypt.swf");

点击LoadMovie后,我收到以下错误:

  

System.AccessViolationException未处理HResult = -2147467261 Message =尝试读取或写入受保护的内存。这通常是一个   指示其他内存已损坏。
  Source = ShockwaveFlashObjects StackTrace:          在ShockwaveFlashObjects.IShockwaveFlash.LoadMovie(Int32图层,字符串网址)          at AxShockwaveFlashObjects.AxShockwaveFlash.LoadMovie(Int32 layer,String url)in   c:\ Windows \ System32 \ AxShockwaveFlashObjects.cs:第685行          在TestActionScript2.Program.Main(String [] args)中的c:\ Something \ trunk \ Src \ TestActionScript2 \ Program.cs:第41行          在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)          在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()          在System.Threading.ExecutionContext.RunInternal(ExecutionContext   executionContext,ContextCallback回调,对象状态,布尔值   preserveSyncCtx)          at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean   preserveSyncCtx)          在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)          在System.Threading.ThreadHelper.ThreadStart()

请帮帮我~~

1 个答案:

答案 0 :(得分:0)

Hy,我遇到了同样的问题,我发现只有在调用LoadMovie beffore表单加载时才会出现此错误。 修复是在Form加载上添加事件并将代码放在那里创建shockwaveflash。

在你的情况下:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.Load += new System.EventHandler(this.Form_Load);
    }

    private void Form_Load(object sender, EventArgs e)
    {
        AxShockwaveFlash player = new AxShockwaveFlash();
        player.CreateControl();
        player.WMode = "transparent";
        player.AllowScriptAccess = "sameDomain";
        player.Loop = false;
        player.LoadMovie(0, @"encrypt.swf");
    }
}