【问题标题】:Loading a Flash movie from a memory stream or a byte array从内存流或字节数组加载 Flash 电影
【发布时间】:2010-12-24 20:23:21
【问题描述】:

我想从内存流或字节数组而不是磁盘上的文件加载 SWF 对象。

AxShockwaveFlash 类提供加载 SWF 的方法和属性,以字符串形式提供其磁盘路径,但我还没有看到其他方法。有一个 InlineData 属性,但通常该类是未记录的,我不知道该属性的作用。能做到吗?

谢谢 F

【问题讨论】:

标签: c# flash activex


【解决方案1】:

我假设您想要做的是在 C# 中而不是在 Flash 本身中初始化它。可以这样做,但这样做有局限性(例如,您可能会遇到奇怪的安全问题)。另一个需要注意的是,这仅在 VS 2010/Flash 10 上进行了测试,但理论上它应该适用于任何版本。

好的,让我们假设您已使用标准机制将 Flash 控件放在表单上。还将您想要的闪存文件添加到资源(或内联字节数组,由您决定)。

然后使用以下代码加载flash文件。

private void InitFlashMovie(AxShockwaveFlash flashObj, byte[] swfFile)
{
    using (MemoryStream stm = new MemoryStream())
    {
        using (BinaryWriter writer = new BinaryWriter(stm))
        {
            /* Write length of stream for AxHost.State */
            writer.Write(8 + swfFile.Length);
            /* Write Flash magic 'fUfU' */
            writer.Write(0x55665566);
            /* Length of swf file */
            writer.Write(swfFile.Length);                    
            writer.Write(swfFile);
            stm.Seek(0, SeekOrigin.Begin);
            /* 1 == IPeristStreamInit */
            flashObj.OcxState = new AxHost.State(stm, 1, false, null);
        }
    }
}

传递表单的 flash 对象和包含要加载的 flash 文件的字节数组,它应该工作。

【讨论】:

    【解决方案2】:

    你就是那个男人
    非常感谢,我正在寻找它,但除了原生 c++ 外没有找到,我试过了,效果很好

    private:void initflash(AxShockwaveFlashObjects::AxShockwaveFlash^ax,array<System::Byte>^data)
            {
                MemoryStream^ ms=gcnew MemoryStream();
                BinaryWriter^ bwr=gcnew BinaryWriter(ms);
                bwr->Write(8+data->Length);
                bwr->Write(0x55665566);
                bwr->Write(data->Length);
                bwr->Write(data);
                ms->Seek(0,SeekOrigin::Begin);
                ax->OcxState=gcnew AxHost::State(ms,1,false,nullptr);
    
                bwr->Close();
                delete bwr;
                ms->Close();
                delete ms;
            }
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                 axShockwaveFlash1->FlashVars="indextext=courses/en0600000000/launch.text.xml&cid=0600000000&l1=en&l2=none";
                 array<System::Byte>^data= File::ReadAllBytes("F:\\Learning\\unformated\\New Folder (3)\\CCNA\\theme\\index.swf");
                 initflash(axShockwaveFlash1,data);
                 SubclassHWND^ s=gcnew SubclassHWND();
                 s->AssignHandle(axShockwaveFlash1->Handle);
             }
    

    最后两行我使用下面的类来防止右键菜单

    ref class SubclassHWND :public NativeWindow
    {
    public:
        SubclassHWND(){}
    protected:
        virtual void WndProc(Message %m) override
              {
                  if(m.Msg==0x204)
                  {
                      return;
                  }
                  NativeWindow::WndProc(m);
              }
    };
    

    【讨论】:

      【解决方案3】:

      VB.net 版本:

      1. 首先添加对 AxShockwaveFlash 的引用
      2. 然后添加此代码。

        Dim swfFile As Byte() = IO.File.ReadAllBytes("C:\Users\root\source\file.swf") Using stm As MemoryStream = New MemoryStream() Using writer As BinaryWriter = New BinaryWriter(stm) writer.Write(8 + swfFile.Length) writer.Write(&H55665566) writer.Write(swfFile.Length) writer.Write(swfFile) stm.Seek(0, SeekOrigin.Begin) AxShockwaveFlash1.OcxState = New AxHost.State(stm, 1, False, Nothing) End Using End Using

      【讨论】:

        猜你喜欢
        • 2010-09-30
        • 1970-01-01
        • 2017-10-31
        • 2014-03-28
        • 1970-01-01
        • 1970-01-01
        • 2011-01-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多