C++与Flash的交互

C++与Flash的交互 

2011-08-11 10:24:03|  分类: VC++ |  标签: |字号 订阅

研究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
}
// 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++的响应");
}
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);
}
}
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);
}
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>");
}
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++, 就可以看到效果了:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值