我试过了,这对我很管用。
我从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);
希望这有帮助:)
谢谢
阿米特