从内存流或字节数组加载 Flash 电影 [英] Loading a Flash movie from a memory stream or a byte array

查看:33
本文介绍了从内存流或字节数组加载 Flash 电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从内存流或字节数组而不是磁盘上的文件加载 SWF 对象.

I want to load an SWF object from a Memory Stream or a byte array instead of a file on disk.

AxShockwaveFlash 类提供了加载 SWF 的方法和属性,以字符串形式提供其磁盘路径,但我还没有看到其他方法.有一个 InlineData 属性,但通常该类是未记录的,我不知道该属性的作用.完全可以做到吗?

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?

谢谢F

推荐答案

我假设您想要做的是在 C# 中而不是在 Flash 本身中初始化它.可以这样做,但这样做是有限制的(例如,您可能会遇到奇怪的安全问题).另一个警告是,这仅在 VS 2010/Flash 10 上进行过测试,但理论上它应该适用于任何版本.

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.

好的,让我们假设您已使用标准机制将 Flash 控件置于表单上.还将您想要的闪存文件添加到资源(或内联字节数组,由您决定).

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).

然后使用以下代码加载flash文件.

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

传递表单的 flash 对象和包含要加载的 flash 文件的字节数组,它应该工作.

Pass the form's flash object and the byte array containing the flash file to load and it should work.

这篇关于从内存流或字节数组加载 Flash 电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆