- 积分
- 136401
- 注册时间
- 2014-12-27
- 最后登录
- 2026-1-23
- 在线时间
- 605 小时
- 威望
- 562
- 贡献
- 29
- 金币
- 52903
- 钢镚
- 1422
- 交易凭证
- 1
- 分享
- 0
- 精华
- 33
- 帖子
- 2094
- 主题
- 1742
TA的每日心情 | 擦汗 2018-4-10 15:18 |
|---|
签到天数: 447 天 [LV.9]以坛为家II
超级版主
    
- 威望
- 562
- 贡献
- 29
- 金币
- 52903
- 钢镚
- 1422
 
|
- //Simple String Echo example
- //mike chambers
- //mchamber@adobe.com
-
- #include <stdlib.h>
- #include <stdio.h>
-
- //Header file for AS3 interop APIs
- //this is linked in by the compiler (when using flaccon)
- #include "AS3.h"
-
- double sum(int num)
- {
- int i;
- double total=0;
- for (i=1;i<=num;i++)
- {
- total += i;
- }
- return total;
- }
-
- //Method exposed to ActionScript
- //Takes a String and echos it
- static AS3_Val echo(void* self, AS3_Val args)
- {
- //9 variable
- int num;
- double total;
- char buf[256];
-
- AS3_ArrayValue(args, "IntType", &num);
-
- total = sum(num);
- sprintf(buf, "%lf", total);
- return AS3_String(buf);
- }
-
- //try new function
- static AS3_Val returnTheSelf(void* self,AS3_Val args){
- //initialize string to null
- char* val = NULL;
-
- //parse the arguments. Expect 1.
- //pass in val to hold the first argument, which
- //should be a string
- AS3_ArrayValue( args, "StrType", &val );
-
- //if no argument is specified
- if(val == NULL)
- {
- char* nullString = "null";
- //return the string "null"
- return AS3_String(nullString);
- }
-
- //otherwise, return the string that was passed in
- return AS3_String(val);
-
- }
-
- //entry point for code
- int main()
- {
- //define the methods exposed to ActionScript
- //typed as an ActionScript Function instance
- AS3_Val echoMethod = AS3_Function( NULL, echo );
- AS3_Val returnTheSelfMethod=AS3_Function(NULL,returnTheSelf);
-
- // construct an object that holds references to the functions
- AS3_Val result = AS3_Object( "echo: AS3ValType,returnTheSelf:AS3ValType", echoMethod ,returnTheSelfMethod);
- //result=AS3_Object("returnTheSelf:AS3ValType",returnTheSelfMethod);
-
- // Release
- AS3_Release( echoMethod );
- AS3_Release(returnTheSelfMethod);
-
- // notify that we initialized -- THIS DOES NOT RETURN!
- AS3_LibInit( result );
-
- // should never get here!
- return 0;
- }
复制代码 如上:
- AS3_Val result = AS3_Object( "echo: AS3ValType,returnTheSelf:AS3ValType", echoMethod ,returnTheSelfMethod);
复制代码 此object中承载了两个方法:echo,returnTheSelf.
本文来自:http://www.cnblogs.com/176170847/archive/2011/01/27/1946206.html
|
|