Flash通过Action Script调用C++接口

适用场景:比如游戏逻辑部分用C++编写,而界面UI则采用flash,程序移植也很方便。

为什么用Adobe Alchemy,Adobe Alchemy有什么优势?

了解 flash AS3 与 C++的异同

Alchemy C/C++ API

安装使用Adobe Alchemy

// 接口编写形式:
#include "AS3.h"
AS3_Val func(void* self, AS3_Val args);// ...

即使没有返回值,不需要传入参数,接口形式也如上,否则不能成功注册。

当编译时出现如下提示,很多情况下貌似可以忽略。

Flash通过Action Script调用C++接口

For example, right before you called AS3_Function, you could have set up some struct or whatever in C, passed that as the data argument, and then you can use that inside of the function that you pass as well.

When you call AS3_Function, you're just setting up a function that can be called by ActionScript later. However, you might want to have some context to that call, and you're allowed to pass that context as data in the first argument.

Declaring a parameter as the void pointer type is kind of like the any type () in AS3, in that it signifies that the data can be of any type. In C, though, you will almost invariably cast the value to a known type so you can access fields from it, like: ((SomeType) data)->someFunction().

From ActionScript, yes, but what happens behind the scenes is a bit different. Your C function will be called with that data pointer that you pass to AS3_Function when you created the callback.

This whole thing is just an Alchemy convention, though, it doesn't really have a lot to do with C.

详见http://www.kirupa.com/forum/showthread.php?356452-C-parameter-doubt


原文链接: https://www.cnblogs.com/pure/archive/2012/05/03/2480229.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/49255

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午12:56
下一篇 2023年2月9日 上午12:57

相关推荐