Loading a Flash movie from a memory stream or a byte array

南笙酒味 提交于 2019-12-18 05:14:06

问题


I want to load an SWF object from a Memory Stream or a byte array instead of a file on disk.

AxShockwaveFlash class provides methods and properties to load an SWF providing its path to disk as a string but I haven't seen another way of doing it. There is an InlineData property but generally the class is undocumented and I don't know what this property does. Can it be done at all?

Thanks F


回答1:


I assume what you are wanting to do is initialize this in C# rather than in Flash itself. It can be done but there are limitations to doing it (for example you may get weird security issues). Another caveat is this has only been tested on VS 2010/Flash 10 but it should work in any version in theory.

Okay, let us assume you have used the standard mechanism to put your flash control on the form. Also add the flash file you want to the resources (or an inline byte array, up to you).

Then use the following code to load the flash file.

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);
        }
    }
}

Pass the form's flash object and the byte array containing the flash file to load and it should work.




回答2:


you are the man
thank you very much i was searching for it but didn't find except for native c++, i tried it and it worked well

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);
         }

the last two lines i'm using the following class to prevent right click menu

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


来源:https://stackoverflow.com/questions/1874077/loading-a-flash-movie-from-a-memory-stream-or-a-byte-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!