我希望能够从内存流或字节数组中加载SWF对象,而不是从磁盘文件中加载。
AxShockwaveFlash类提供了通过将其路径作为字符串提供来加载SWF的方法和属性,但我没有看到其他方法。虽然有InlineData属性,但通常该类未经记录,我不知道此属性的作用。这是否可以做到?
谢谢 F
我猜你想要的是在C#中初始化这个东西,而不是在Flash本身中进行初始化。尽管可以做到,但这样做有一些限制(例如,可能会出现奇怪的安全问题)。另一个注意事项是,这仅在 VS 2010 / Flash 10 上进行过测试,但理论上应该在任何版本上都能工作。
好的,让我们假设你已经使用标准机制将flash控件放在表单上。还要将所需的flash文件添加到资源中(或内联字节数组,由你决定)。
然后使用以下代码加载flash文件。
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);
}
}
}
将表单的闪存对象和包含要加载的闪存文件的字节数组传递给它,它 应该 可以工作。
你真是个牛人
非常感谢,我一直在寻找相关的资料,但除了本地的C++,没有找到其他的方法。我尝试了它并且它运行良好。
private:void initflash(AxShockwaveFlashObjects::AxShockwaveFlash^ax,array<System::Byte>^data)
{
MemoryStream^ ms=gcnew MemoryStream();
BinaryWriter^ bwr=gcnew BinaryWriter(ms);
bwr->Write(8+data->Length);
bwr->Write(0x55665566);
bwr->Write(data->Length);
bwr->Write(data);
ms->Seek(0,SeekOrigin::Begin);
ax->OcxState=gcnew AxHost::State(ms,1,false,nullptr);
bwr->Close();
delete bwr;
ms->Close();
delete ms;
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
axShockwaveFlash1->FlashVars="indextext=courses/en0600000000/launch.text.xml&cid=0600000000&l1=en&l2=none";
array<System::Byte>^data= File::ReadAllBytes("F:\\Learning\\unformated\\New Folder (3)\\CCNA\\theme\\index.swf");
initflash(axShockwaveFlash1,data);
SubclassHWND^ s=gcnew SubclassHWND();
s->AssignHandle(axShockwaveFlash1->Handle);
}
最后两行代码使用以下类来防止右键菜单:
ref class SubclassHWND :public NativeWindow
{
public:
SubclassHWND(){}
protected:
virtual void WndProc(Message %m) override
{
if(m.Msg==0x204)
{
return;
}
NativeWindow::WndProc(m);
}
};
VB.net版本:
然后添加以下代码。
Dim swfFile As Byte() = IO.File.ReadAllBytes("C:\Users\root\source\file.swf")
Using stm As MemoryStream = New MemoryStream()
Using writer As BinaryWriter = New BinaryWriter(stm)
writer.Write(8 + swfFile.Length)
writer.Write(&H55665566)
writer.Write(swfFile.Length)
writer.Write(swfFile)
stm.Seek(0, SeekOrigin.Begin)
AxShockwaveFlash1.OcxState = New AxHost.State(stm, 1, False, Nothing)
End Using
End Using