您的位置:首页 > 编程语言 > C语言/C++

C++与Flash的交互

2011-12-02 17:14 232 查看
/article/1656229.html

研究Flash嵌入游戏中的可行性.......

渲染问题已解决
事件响应已解决
下面是C++与Flash AS的交互, 以MFC为例:

1. 新建一个MFC Dialog程序

2. 添加一个Flash控件





3. 把Flash控件添加一个变量





4. 在OnInitDialog()中添加载.swf文件

view plaincopy to
clipboardprint?

// CCppFlashDlg 消息处理程序

BOOL CCppFlashDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标

// TODO: 在此添加额外的初始化代码
this->flashUI.LoadMovie(0, "C://Documents and Settings//Administrator//My Documents//My Flash//HelloWorld.swf");
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}

5. 制作一个flash, 放一个Button上去, 导出一下就可以在MFC中看到了





6. flash调用C++.

这个很简单, 在flash的那个Button组件的动作中添加脚本:

view plaincopy to
clipboardprint?

on(click)
{
fscommand("MsgBox", "这是flash调用c++的响应");

}

然后在MFC中添加事件响应:





view plaincopy to
clipboardprint?

void CCppFlashDlg::FSCommandShockwaveflash1(LPCTSTR command, LPCTSTR args)

{
// TODO: Add your message handler code here

if (0 == strcmp("MsgBox", command))

{
MessageBox(args);
}
}

7. C++调用Flash.

首先在Flash中注册回调函数:

view plaincopy to
clipboardprint?

import mx.controls.Alert;

import flash.external.*;

ExternalInterface.addCallback("MsgBox", this, MsgBox);

function MsgBox(msg:String)

{
Alert.show(msg, "",Alert.OK);

}

然后在C++中添加调用:

view plaincopy to
clipboardprint?

void CCppFlashDlg::OnOK()

{
// TODO: Add your specialized code here and/or call the base class

this->flashUI.CallFunction("/

<invoke name=/"MsgBox/">/

<arguments>/
<string>这是C++调用flash的响应</string>/
</arguments>/
</invoke>");
}

另外, 还可以通过GetVariable()和SetVariable()来设置flash中定义的变量

8. 导出一下flash, 编译一下C++, 就可以看到效果了:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: