我试过了,它对我有用。
我从 AxShockwaveFlashObjects.AxShockwaveFlash 派生了一个类并实现了 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);
希望这会有所帮助:)
谢谢
阿米特