GLP
GLP

Reputation: 31

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

Upvotes: 3

Views: 3254

Answers (3)

Hao Nguyen
Hao Nguyen

Reputation: 536

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.

Upvotes: 2

KSK
KSK

Reputation: 695

Try this. Make a blank swf. "Blank.swf" load it first and then re-load your game.

axShockwaveFlash1.LoadMovie(0,"Blank.swf");
axShockwaveFlash1.Play();
axShockwaveFlash1.LoadMovie(0, Form1.currentGame);
axShockwaveFlash1.Play();

Ensure you give the correct path for the Blank.swf.

Upvotes: 1

lowie
lowie

Reputation: 11

Have you tried loading an "empty" flash video before loading your new video?

e.g.

axShockwaveFlash1.LoadMovie(0,"");

I'm sure that I encountered a similar problem and resolved it this way.

Upvotes: 1

Related Questions