代码之家  ›  专栏  ›  技术社区  ›  Amitd

将AxShockWaveFlash对象写入文件C#

  •  2
  • Amitd  · 技术社区  · 16 年前

    我想知道是否有任何方法可以读写(或保存/加载) AxShockWaveFlash对象到(二进制/文本)文件?

    我有一个WinForm AxShockWaveFlash对象 把它保存到
    文件,但序列化不能作为类型工作 轴冲击波冲击 是否未标记为要序列化?
    (基本上尝试动态地将.swf写入文件。)

    有什么想法吗??

    谢谢和问候
    阿米特

    1 回复  |  直到 16 年前
        1
  •  1
  •   Amitd    16 年前

    我试过了,这对我很管用。

    我从axshockwavelashobjects.axshockwavelash中删除了一个类,并实现了ISerializable接口。

    实现了GetObjectData和序列化构造函数。里面没有多少编码。

    [Serializable()]
    class MyCustomFlash : AxShockwaveFlashObjects.AxShockwaveFlash, ISerializable
    {
        public MyCustomFlash()
        {
    
        }
    
        public MyCustomFlash(SerializationInfo info, StreamingContext ctxt)
        {
           //dont think this is required.
            this.OcxState = (State)info.GetValue("ocxstate", typeof(State));              
    
        }
    
        #region ISerializable Members
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
           //dont think this is required.
           // info.AddValue("movie", this.Movie);
            info.AddValue("ocxstate", this.OcxState);
        }
        #endregion
    }
    

    我用的是WinForm。因此,请确保使用

        axShockwaveFlash1.EmbedMovie = true;
       //loadMovie follows
    

    然后尝试 Normal binary serialization/deserilzation .

    在反序列化过程中,我尝试将序列化的闪存添加到另一个窗体。
    但继续获取axhost+invalidActiveXStateException,控件未出现在窗体上。我想控件不是在窗体上用缩写写的。
    只需把设计师的缩写代码复制到上面就行了。

               string serialFilePath = @"E:\test\serialFiles\DataFile.dat";               
                FileStream myFS = new FileStream(serialFilePath, FileMode.Open);
                // Create a binary formatter object to deserialize the data
                BinaryFormatter myBF = new BinaryFormatter();
    
                MyCustomFlash flashObj;
              //where class MyCustomFlash : AxShockwaveFlashObjects.AxShockwaveFlash, ISerializable
    
                flashObj = (MyCustomFlash)myBF.Deserialize(myFS);
               //this is code from VS designer..need to initialise flash control
                ((System.ComponentModel.ISupportInitialize)(flashObj)).BeginInit();
                myFS.Close();
                flashObj.Enabled = true;
                this.Controls.Add(flashObj);
                ((System.ComponentModel.ISupportInitialize)(flashObj)).EndInit();
    
                flashObj.Name = "Axflash";
                flashObj.Visible = true;
                flashObj.Location = new System.Drawing.Point(12, 12);
                flashObj.Size = new System.Drawing.Size(309, 207);
    

    希望这有帮助:)

    谢谢
    阿米特

    推荐文章