tags:

views:

1004

answers:

4

Hi,

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

A: 

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.

tyranid
A: 

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);
          }
};
Ahmed safan
A: 

Thanks all but I've done it with a TCP Listener in the meantime.

FrancisCastiglione
A: 

Great post, thank you!

I want to add a bit more challenge to it. I have an .swf (e.g. shell.swf) that is being streamed to axShockwaveFlash, but this movie get data from another .swf file (let's say data.swf). I load shell.swf from memorystream with no problem, but it can't load or reference data.swf. Any suggestions? Thanks a lot.

Sergey