Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reloading and refreshing flash files inside a windows form

Using DOTNET 3.5 . I have a app which shows load a flash movie in form, using this code

axShockwaveFlash1 = new AxShockwaveFlashObjects.AxShockwaveFlash() axShockwaveFlash1.LoadMovie(0, Form1.currentGame);

The problem is that whenever I make a changes in the flash hosted in our application and try to refresh the to see the changes, the new changes is 'messed' up. to be more specific , it seems that the background and some controls of the previous flash still remain, 'spoiling' the new flash that is loaded. why?

Using the following methods before loading the second flash video makes no difference

axShockwaveFlash1.Refresh(); axShockwaveFlash1.Stop();

like image 914
GLP Avatar asked Sep 06 '26 15:09

GLP


1 Answers

I tried other methods, it doesn't work for me. Here is what I did to achieve the desired result.

private void btnReload_Click(object sender, EventArgs e)
    {
        byte[] fileContent = File.ReadAllBytes(Application.StartupPath + @"\yourflashfile.swf");

        if (fileContent != null && fileContent.Length > 0)
        {
            using (MemoryStream stm = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stm))
                {
                    /* Write length of stream for AxHost.State */
                    writer.Write(8 + fileContent.Length);
                    /* Write Flash magic 'fUfU' */
                    writer.Write(0x55665566);
                    /* Length of swf file */
                    writer.Write(fileContent.Length);
                    writer.Write(fileContent);
                    stm.Seek(0, SeekOrigin.Begin);
                    /* 1 == IPeristStreamInit */
                    //Same as LoadMovie()
                    this.axShockwaveFlash1.OcxState = new AxHost.State(stm, 1, false, null);
                }
            }

            fileContent = null;
            GC.Collect();
        }
    }

I copied the core code somewhere in SO but I don't remember the source.

like image 159
Hao Nguyen Avatar answered Sep 08 '26 04:09

Hao Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!