我想知道是否有任何方法可以将AxShockwaveFlash Flash对象读写(或保存/加载)到(二进制/文本)文件?。
我有一个带有AxShockwaveFlash Flash 的Winform,希望将它保存到
文件,但是序列化不工作,因为类型AxShockwaveFlash没有标记为序列化?
(基本上是试图动态地将.swf写入文件。)
有什么主意吗?
感谢并致以问候
阿米特
发布于 2010-02-03 07:32:19
我试过了它对我有用。
我从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那就试试正常二进制序列化/荒漠化。
在反序列化过程中,我尝试将序列化的闪存添加到另一个窗体中。
但是继续获取AxHost+InvalidActiveXStateException,控件没有出现在表单上。我认为控制不是在表格上输入的。
只要将设计器初始化代码复制到它,.and,它就能工作了。
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);希望这会有所帮助:)
thx
阿米德
https://stackoverflow.com/questions/2174854
复制相似问题