开发者

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 befor开发者_JS百科e loading the second flash video makes no difference

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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜