Loading a Flash movie from a memory stream or byte array

I want to load a SWF object from a memory stream or byte array instead of a file on disk.

The AxShockwaveFlash class provides methods and properties for loading SWF, providing its path to the disk as a string, but I have not seen another way to do this. There is an InlineData property, but usually the class is undocumented, and I don't know what it does. Can this be done at all?

Thanks f

+3
source share
2 answers

I guess what you want to do is initialize this in C #, and not in Flash itself. This can be done, but there are limitations to this (for example, you may get strange security issues). Another caveat is only testing on VS 2010 / Flash 10, but it should work in any version in theory.

Well, let's say you used a standard mechanism to put the flash controls on the form. Also add the flash file that you want to use for the resources (or the built-in byte array, up to you).

Then use the following code to download 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 flash object of the form and an array of bytes containing the loaded flash file, and it should work.

+9
source


, , , ++, ,

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

Source: https://habr.com/ru/post/1725160/


All Articles