守望者--AIR技术交流

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
热搜: ANE FlasCC 炼金术
查看: 3536|回复: 2
打印 上一主题 下一主题

[文档资料] AS3++.h API文档

[复制链接]
  • TA的每日心情
    擦汗
    2018-4-10 15:18
  • 签到天数: 447 天

    [LV.9]以坛为家II

    1742

    主题

    2094

    帖子

    13万

    积分

    超级版主

    Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

    威望
    562
    贡献
    29
    金币
    52694
    钢镚
    1422

    开源英雄守望者

    跳转到指定楼层
    楼主
    发表于 2014-12-29 23:16:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    Adobe Flash C++ Compiler (FlasCC)

    A complete BSD-like C/C++ development environment with a GCC based cross-compiler capable of targeting the Adobe Flash Runtime.


    C/C++ API ReferenceAS3++.h

    The AS3++.h header file contains macros that help you quickly create C++ instances of ActionScript3 (AS3) objects.

    In order to use the AS3++ library you will need to #include <AS3/AS3++.h> and pass the -lAS3++ compiler argument to g++, for example:

    1. /flascc/sdk/usr/bin/g++ sample.cpp -emit-swf -o sample.swf -lAS3++
    复制代码

    Some of the examples on this page also use the Flash++ library. Be sure to include the correct compiler arguments when compiling those examples.

    Class:var

    The var class is a C++ representation of an ActionScript object. It could be a scalar or an object similar to how ActionScript's * special type works. All objects and properties of Flash++ classes have var as a base type. In order to work with var objects you can use some of the helper functions listed below.

    For example if you have a Date object and ask for its fullYear property that will be returned as a var. Printing the value of that var directly as a decimal won't be very useful:

    1. #include <Flash++.h>
    2. #include <stdio.h>

    3. using namespace AS3::local;

    4. int main(){
    5.     Date myDate = Date::_new();

    6.     printf("%d\n", myDate->fullYear); // output: 7
    7. }
    复制代码

    Instead you might want to use the internal::int_valueOf() function to convert the value of that var into a scalar integer:

    1. #include <Flash++.h>
    2. #include <stdio.h>

    3. using namespace AS3::local;

    4. int main(){
    5.     Date myDate = Date::_new();

    6.     int year = AS3::local::internal::int_valueOf(myDate->fullYear);
    7.     printf("%d\n", year); // output: 2012
    8. }
    复制代码
    Namespace:AS3
    Function Description
    sz2stringAndFree
    1. inline std::string sz2stringAndFree(const char *s);
    复制代码

    Turns a null-terminated char* into a std::string and frees the memory it used in the process.

    Parameters:

    • s - C character string to be converted into a std::string.

    Example Usage:

    1. #include <Flash++.h>
    2. #include <stdio.h>

    3. using namespace AS3::local;

    4. int main() {
    5.     Date myDate = Date::_new();
    6.     std::string dateStr = AS3::sz2stringAndFree(internal::utf8_toString(myDate));
    7.     printf("%s\n", dateStr.c_str()); // output: Sat Nov 10 09:29:53 GMT-0800 2012
    8. }
    复制代码


    Namespace: AS3::local::internal or AS3::ui::internal

    Each of the following functions comes in two variants. The first variant is the “local” variant in namespace AS3::local. These functions operate on AS3 values in the context of the executing Worker. This means that access to mouse or keyboard input, Clipboard, etc. will not work outside of the primordial or “UI” Worker. Cross-Worker sharing of these types will result in (hard to debug!) runtime errors. This means that they should not be shared across Pthreads.

    The second variant is the “ui” variant in namespace AS3::ui. These functions operate on AS3 values that are maintained in the primordial/UI Worker. As accesses to these types are automatically delegated to the primordial/UI Worker, they may be shared across Workers/Pthreads and may be used to access UI features from any Worker/Pthread. There is some performance overhead to this delegation, and these types should be used with caution in performance-sensitive code.

    The example code on this page is single threaded and doesn't interact with the mouse/keyboard/stage/etc. so it uses the AS3::local namespace by default.


    FunctionDescription
    new_int

    1. var new_int(int n);
    复制代码
    Create an AS3 int object.
    Parameters:
    • n - int value.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_int(5);
    5.    
    6.     // show the type and value of that var
    7.     char* type = AS3::local::internal::utf8_toString(AS3::local::internal::_typeof(x));
    8.     int value = AS3::local::internal::int_valueOf(x);
    9.     printf("type: %s, value: %d\n", type, value); // output: type: number, value: 5
    10.     free(type);
    11. }
    复制代码
    Also see the 10_MessageChannel sample
    new_uint

    1. var new_uint(unsigned n);
    复制代码
    Create an AS3 uint object.
    Parameters:
    • n - unsigned integer value.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_uint(5);
    5.    
    6.     // show the type and value of that var
    7.     char* type = AS3::local::internal::utf8_toString(AS3::local::internal::_typeof(x));
    8.     unsigned value = AS3::local::internal::uns_valueOf(x);
    9.     printf("type: %s, value: %d\n", type, value); // output: type: number, value: 5
    10.     free(type);
    11. }
    复制代码
    new_Number

    1. var new_Number(double n);
    复制代码
    Create an AS3 Number object.
    Parameters:
    • n - double value.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_Number(5.5);
    5.    
    6.     // show the type and value of that var
    7.     char* type = AS3::local::internal::utf8_toString(AS3::local::internal::_typeof(x));
    8.     double value = AS3::local::internal::double_valueOf(x);
    9.     printf("type: %s, value: %f\n", type, value); // output: type: number, value: 5.500000
    10.     free(type);
    11. }
    复制代码
    Also see the 12_Stage3D sample
    new_Boolean

    1. var new_Boolean(bool b);
    复制代码
    Create an AS3 Boolean object.
    Parameters:
    • b - boolean value.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_Boolean(true);
    5.    
    6.     bool value = AS3::local::internal::bool_valueOf(x);
    7.    
    8.     if (value)
    9.         printf("x == true"); // output: x == true
    10. }
    复制代码
    new_String

    1. var new_String(const char *s, int len = -1);
    复制代码
    Create an AS3 String object. If len is set to -1 then strlen is called on the string to calculate its length. Explicitly providing len means the string does not need to be null-terminated and avoids the call to strlen.
    Parameters:
    • s - C character string containing the AS3 String to be created.
    • len (optional) - Length of the C character string s.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_String("hello");
    5.    
    6.     char* str = AS3::local::internal::utf8_toString(x);
    7.     printf("%s\n", str); // output: hello
    8.     free(str);
    9. }
    复制代码
    Also see the 10_MessageChannel sample
    new_Namespace

    1. var new_Namespace(const char *s, int len = -1);
    复制代码
    Create an AS3 Namespace object. If len is set to -1 then strlen is called on the string to calculate its length. Explicitly providing len means the string does not need to be null-terminated and avoids the call to strlen.
    Parameters:
    • s - C character string containing the name of the namespace to be created.
    • len (optional) - Length of the C character string s.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <Flash++.h>
    3. #include <stdio.h>

    4. using namespace AS3::local;

    5. int main() {
    6.     // create a class closure that represents the MouseEvent class
    7.     AS3::local::var ns = AS3::local::internal::new_Namespace("flash.events", 12);
    8.     AS3::local::var className = AS3::local::internal::new_String("MouseEvent");
    9.     AS3::local::var cc = AS3::local::internal::getlex(ns, className);
    10.    
    11.     // construct a MouseEvent object
    12.     AS3::local::var arg1 = AS3::local::internal::new_String("mouseDown");
    13.     AS3::local::var event = AS3::local::internal::construct(cc, arg1);
    14.    
    15.     char* strEvent = AS3::local::internal::utf8_toString(event);
    16.     printf("event=%s\n", strEvent); // output: event=[MouseEvent type="mouseDown" ...
    17.     free(strEvent);
    18. }
    复制代码
    new_Array

    1. var new_Array(int count, var *elems);
    复制代码
    Create an AS3 Array containing references to the specified AS3 vars.
    Parameters:
    • count - int specifying the number of elements in the Array.
    • elems - array of var objects.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x1 = AS3::local::internal::new_int(5);
    5.     AS3::local::var x2 = AS3::local::internal::new_int(6);
    6.     AS3::local::var nums[2] = {x1, x2};
    7.     AS3::local::var myArray = AS3::local::internal::new_Array(2, nums);
    8.    
    9.     char* str = AS3::local::internal::utf8_toString(myArray);
    10.     printf("myArray=%s\n", str); // output: myArray=5,6
    11.     free(str);
    12. }
    复制代码
    new_Function

    1. var new_Function(var (*fun)(void *data, var args), void *data);
    复制代码
    Create an AS3 Function object of a C function pointer.         The C function must declare two parameters: a void* that represents the passed in C context, and a var that represents the AS3 parameters that were passed to this Function when it is called.
    Parameters:
    • fun - C function pointer that will be wrapped by the returned AS3 Function.
    • data - Arbitrary data that is passed to the first parameter of the C function. May be used to provide the C function context.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. AS3::local::var square(void *arg, AS3::local::var as3Args) {
    4.     // C argument
    5.     int x = (int) arg;
    6.    
    7.     // AS3 arguments
    8.     AS3::local::var test1 = as3Args[0];
    9.     AS3::local::var test2 = as3Args[1];
    10.    
    11.     printf("C arg: %d\n", x); // output: C arg: 5
    12.    
    13.     printf("as3Args: %d, %d\n",
    14.            AS3::local::internal::int_valueOf(test1),
    15.            AS3::local::internal::int_valueOf(test2)); // output: as3Args: 5, 6
    16.    
    17.     return AS3::local::internal::new_String("hello");
    18. }

    19. int main() {
    20.     // create some AS3 arguments to pass to the function
    21.     AS3::local::var x1 = AS3::local::internal::new_int(5);
    22.     AS3::local::var x2 = AS3::local::internal::new_int(6);
    23.     AS3::local::var nums[2] = {x1, x2};
    24.     AS3::local::var argsArray = AS3::local::internal::new_Array(2, nums);
    25.    
    26.     // create the Function var
    27.     AS3::local::var myFun = AS3::local::internal::new_Function(square, (void*) 5);   
    28.    
    29.     // call the Function
    30.     AS3::local::var rcv = AS3::local::internal::_null;
    31.     AS3::local::var res = AS3::local::internal::call_v(myFun, rcv, argsArray);
    32.    
    33.     // show the return value
    34.     char* resultString = AS3::local::internal::utf8_toString(res);
    35.     printf("result=%s\n", resultString); // output: result=hello
    36.     free(resultString);
    37. }
    复制代码
    Also see the 10_MessageChannel sample and the handling mouse input Flash++ example.
    new_Vector

    1. var new_Vector(var cc);
    复制代码
    Create an AS3 Vector.<cc>, where cc is a class closure.
    Parameters:
    • cc - var containing a class closure.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <Flash++.h>
    3. #include <stdio.h>

    4. using namespace AS3::local;

    5. int main() {
    6.     // create a class closure that represents the MouseEvent class
    7.     AS3::local::var ns = AS3::local::internal::new_Namespace("flash.events", 12);
    8.     AS3::local::var className = AS3::local::internal::new_String("MouseEvent");
    9.     AS3::local::var cc = AS3::local::internal::getlex(ns, className);
    10.    
    11.     // create a Vector of MouseEvents
    12.     AS3::local::var v = AS3::local::internal::new_Vector(cc);
    13.     v[0] = flash::events::MouseEvent::_new(AS3::local::internal::new_String("mouseDown"));
    14.     v[1] = flash::events::MouseEvent::_new(AS3::local::internal::new_String("mouseUp"));
    15.     v[2] = flash::events::MouseEvent::_new(AS3::local::internal::new_String("mouseClick"));
    16.    
    17.     char* vStr = AS3::local::internal::utf8_toString(v);
    18.     printf("v=%s\n", vStr); // output: v=[MouseEvent type="mouseDown" ...
    19.     free(vStr);
    20. }
    复制代码
    new_Vector_int

    1. var new_Vector_int();
    复制代码
    Create an AS3 Vector of type int.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var v = AS3::local::internal::new_Vector_int();
    5.     v[0] = AS3::local::internal::new_int(0);
    6.     v[1] = AS3::local::internal::new_int(1);
    7.     v[2] = AS3::local::internal::new_int(2);
    8.    
    9.     char* vStr = AS3::local::internal::utf8_toString(v);
    10.     printf("v=%s\n", vStr); // output: v=0,1,2
    11.     free(vStr);
    12. }
    复制代码
    new_Vector_uint

    1. var new_Vector_uint();
    复制代码
    Create an AS3 Vector of type uint.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     // create a Vector of uints
    5.     AS3::local::var v = AS3::local::internal::new_Vector_uint();
    6.     v[0] = AS3::local::internal::new_uint(0);
    7.     v[1] = AS3::local::internal::new_uint(1);
    8.     v[2] = AS3::local::internal::new_uint(2);
    9.    
    10.     char* vStr = AS3::local::internal::utf8_toString(v);
    11.     printf("v=%s\n", vStr); // output: v=0,1,2
    12.     free(vStr);
    13. }
    复制代码
    new_Vector_Boolean

    1. var new_Vector_Boolean();
    复制代码
    Create an AS3 Vector of type Boolean.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     // create a Vector of Booleans
    5.     AS3::local::var v = AS3::local::internal::new_Vector_Boolean();
    6.     v[0] = AS3::local::internal::_true;
    7.     v[1] = AS3::local::internal::_false;
    8.     v[2] = AS3::local::internal::_true;
    9.    
    10.     char* vStr = AS3::local::internal::utf8_toString(v);
    11.     printf("v=%s\n", vStr); // output: v=true,false,true
    12.     free(vStr);
    13. }
    复制代码
    new_Vector_String

    1. var new_Vector_String();
    复制代码
    Create an AS3 Vector of type String.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     // create a Vector of Strings
    5.     AS3::local::var v = AS3::local::internal::new_Vector_String();
    6.     v[0] = AS3::local::internal::new_String("a");
    7.     v[1] = AS3::local::internal::new_String("b");
    8.     v[2] = AS3::local::internal::new_String("c");
    9.    
    10.     char* vStr = AS3::local::internal::utf8_toString(v);
    11.     printf("v=%s\n", vStr); // output: v=a,b,c
    12.     free(vStr);
    13. }
    复制代码
    new_Vector_Number

    1. var new_Vector_Number();
    复制代码
    Create an AS3 Vector of type Number.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     // create a Vector of Numbers
    5.     AS3::local::var v = AS3::local::internal::new_Vector_Number();
    6.     v[0] = AS3::local::internal::new_Number(1.1);
    7.     v[1] = AS3::local::internal::new_Number(2.2);
    8.     v[2] = AS3::local::internal::new_Number(3.3);
    9.    
    10.     char* vStr = AS3::local::internal::utf8_toString(v);
    11.     printf("v=%s\n", vStr); // output: v=1.1,2.2,3.3
    12.     free(vStr);
    13. }
    复制代码
    Also see the 12_Stage3D sample
    new_undefined

    1. var new_undefined();
    复制代码
    Create an AS3 undefined object. See _undefined.
    new_null

    1. var new_null();
    复制代码
    Create an AS3 null object. See _null.
    1. template <typename T> T new_null()
    复制代码
    Create an AS3 null object of type T. See _null.
    get_Worker

    1. var get_Worker(long tid = -1);
    复制代码
    Get a reference to the Worker object for a given thread id.
    Parameters:
    • tid (optional) - A BSD-like thread id which comes from the thr_self call in sys/thr.h. The default is -1, which indicates the currently running thread.
    Example Usage:
    See the 10_MessageChannel sample

    get_ram

    1. var get_ram();
    复制代码
    Get a reference to the currently assigned domainMemory ByteArray.
    Example Usage:
    See the 10_MessageChannel sample
    _undefined

    1. extern const var _undefined;
    复制代码
    The AS3 undefined var.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. // sample function that demonstrates how to return an undefined value
    4. AS3::local::var goodValue(void *arg, AS3::local::var as3Args) {
    5.     int arg1 = AS3::local::internal::int_valueOf(as3Args[0]);
    6.    
    7.     if (arg1 > 0)
    8.         return AS3::local::internal::new_String("valid");
    9.     else
    10.         return AS3::local::internal::_undefined;
    11. }

    12. int main() {
    13.     // create the Function var
    14.     AS3::local::var myFun = AS3::local::internal::new_Function(goodValue, NULL);   
    15.    
    16.     // create the arguments to pass to the function
    17.     AS3::local::var arg1 = AS3::local::internal::new_int(0);
    18.     AS3::local::var args[1] = {arg1};
    19.    
    20.     // call the Function
    21.     AS3::local::var rcv = AS3::local::internal::_null;
    22.     AS3::local::var output = AS3::local::internal::call(myFun, rcv, 1, args);
    23.    
    24.     // show the return value
    25.     char* resultString = AS3::local::internal::utf8_toString(output);
    26.     printf("result=%s\n", resultString); // output: result=undefined
    27.     free(resultString);
    28. }
    复制代码
    Also see the 12_Stage3D sample
    _null

    1. extern const var _null;
    复制代码
    The AS3 null var.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. // sample function that demonstrates how to return a null value
    4. AS3::local::var goodValue(void *arg, AS3::local::var as3Args) {
    5.     int arg1 = AS3::local::internal::int_valueOf(as3Args[0]);
    6.    
    7.     if (arg1 > 0)
    8.         return AS3::local::internal::new_String("valid");
    9.     else
    10.         return AS3::local::internal::_null;
    11. }

    12. int main() {
    13.     // create the Function var
    14.     AS3::local::var myFun = AS3::local::internal::new_Function(goodValue, NULL);   
    15.    
    16.     // create the arguments to pass to the function
    17.     AS3::local::var arg1 = AS3::local::internal::new_int(0);
    18.     AS3::local::var args[1] = {arg1};
    19.    
    20.     // call the Function
    21.     AS3::local::var rcv = AS3::local::internal::_null;
    22.     AS3::local::var output = AS3::local::internal::call(myFun, rcv, 1, args);
    23.    
    24.     // show the return value
    25.     char* resultString = AS3::local::internal::utf8_toString(output);
    26.     printf("result=%s\n", resultString); // output: result=null
    27.     free(resultString);
    28. }
    复制代码
    Also see the 09_Pthreads sample
    _true

    1. extern const var _true;
    复制代码
    The AS3 true var.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     // create a Boolean var that is initially false
    5.     AS3::local::var x = AS3::local::internal::new_Boolean(false);

    6.     // then set it to the _true var
    7.     x = AS3::local::internal::_true;

    8.     // show the value
    9.     if (AS3::local::internal::bool_valueOf(x))
    10.         printf("x == true"); // output: x == true
    11.     else
    12.         printf("x == false");
    13. }
    复制代码
    _false

    1. extern const var _false;
    复制代码
    The AS3 false var.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     // create a Boolean var that is initially true
    5.     AS3::local::var x = AS3::local::internal::new_Boolean(true);

    6.     // then set it to the _false var
    7.     x = AS3::local::internal::_false;

    8.     // show the value
    9.     if (AS3::local::internal::bool_valueOf(x))
    10.         printf("x == true");
    11.     else
    12.         printf("x == false"); // output: x == false
    13. }
    复制代码
    _typeof

    1. var _typeof(var val);
    复制代码
    Equivalent to the AS3 typeof operator, which returns a String representation of the type of the AS3 object.
    Parameters:
    • val - var containing the value for which the AS3 type is returned.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var myObject = AS3::local::internal::new_String("Hello");
    5.     AS3::local::var myObjectType = AS3::local::internal::_typeof(myObject);
    6.    
    7.     char* str = AS3::local::internal::utf8_toString(myObjectType);
    8.     printf("type=%s\n",str); // output: type=string
    9.     free(str);
    10. }
    复制代码
    equals

    1. bool equals(var a, var b);
    复制代码
    Equivalent to the AS3 equality operator "==".
    Other similar functions include:
      1. bool strictequals(var a, var b);
      复制代码

      1. bool lessthan(var a, var b);
      复制代码

      1. bool lessequals(var a, var b);
      复制代码

      1. bool greaterthan(var a, var b);
      复制代码

      1. bool greaterequals(var a, var b);
      复制代码

    Parameters:
    • a - var containing an AS3 object.
    • b - var containing an AS3 object.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var e1 = AS3::local::internal::new_String("5");
    5.     AS3::local::var e2 = AS3::local::internal::new_Number(5);
    6.    
    7.     bool equal = AS3::local::internal::equals(e1, e2);
    8.     bool strictEqual = AS3::local::internal::strictequals(e1, e2);
    9.    
    10.     if (equal)
    11.         printf("e1 == e2"); // output: e1 == e2
    12.     if (strictEqual)
    13.         printf("e1 === e2");
    14. }
    复制代码
    call_v

    1. var call_v(var fun, var rcv, var vargs, void *ramPos = (void *)-1);
    复制代码
    Use Function.apply to call a Function object with an Array of arguments.
    Parameters:
    • fun - var that represents a C function pointer (see new_Function).
    • rcv - var equivalent to the thisArg parameter of Function.apply.
    • vargs - var that contains an AS3 Array of vars to pass as arguments to the function (see new_Array).
    • ramPos (optional) - the position to set on the domainMemory ByteArray before executing the function. For example, useful when calling setPixels with the domainMemory as an argument.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. AS3::local::var square(void *arg, AS3::local::var as3Args) {
    4.     // AS3 arguments
    5.     AS3::local::var test1 = as3Args[0];
    6.     AS3::local::var test2 = as3Args[1];
    7.    
    8.     printf("as3Args=%d, %d\n",
    9.            AS3::local::internal::int_valueOf(test1),
    10.            AS3::local::internal::int_valueOf(test2)); // output: as3args=5, 6
    11.    
    12.     return AS3::local::internal::new_String("hello");
    13. }

    14. int main() {
    15.     // create some AS3 arguments to pass to the function
    16.     AS3::local::var x1 = AS3::local::internal::new_int(5);
    17.     AS3::local::var x2 = AS3::local::internal::new_int(6);
    18.     AS3::local::var nums[2] = {x1, x2};
    19.     AS3::local::var argsArray = AS3::local::internal::new_Array(2, nums);
    20.    
    21.     // create the Function var
    22.     AS3::local::var myFun = AS3::local::internal::new_Function(square, NULL);   
    23.    
    24.     // call the Function
    25.     AS3::local::var rcv = AS3::local::internal::_null;
    26.     AS3::local::var output = AS3::local::internal::call_v(myFun, rcv, argsArray);
    27.    
    28.     // show the return value
    29.     char* resultString = AS3::local::internal::utf8_toString(output);
    30.     printf("result=%s\n", resultString); // output: result=hello
    31.     free(resultString);
    32. }
    复制代码
    call

    1. var call(var fun, var rcv, int argCount, var *args, void *ramPos = (void *)-1);
    复制代码
    Use Function.apply to call a Function object with the arguments array constructed automatically.
    Parameters:
    • fun - var that represents a C function pointer (see new_Function).
    • rcv - var equivalent to the thisArg parameter of Function.apply.
    • argCount - int specifying the number of arguments.
    • args - array of vars that are passed as arguments to the function.
    • ramPos (optional) - the position to set on the domainMemory ByteArray before executing the function. For example, useful when calling setPixels with the domainMemory as an argument.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. AS3::local::var square(void *arg, AS3::local::var as3Args) {
    4.     // AS3 arguments
    5.     AS3::local::var test1 = as3Args[0];
    6.     AS3::local::var test2 = as3Args[1];
    7.    
    8.     printf("as3Args=%d, %d\n",
    9.            AS3::local::internal::int_valueOf(test1),
    10.            AS3::local::internal::int_valueOf(test2)); // output: as3Args=5,6
    11.    
    12.     return AS3::local::internal::new_String("hello");
    13. }

    14. int main() {
    15.     // create some AS3 arguments to pass to the function
    16.     AS3::local::var x1 = AS3::local::internal::new_int(5);
    17.     AS3::local::var x2 = AS3::local::internal::new_int(6);
    18.     AS3::local::var nums[2] = {x1, x2};
    19.    
    20.     // create the Function var
    21.     AS3::local::var myFun = AS3::local::internal::new_Function(square, NULL);   
    22.    
    23.     // call the Function
    24.     AS3::local::var rcv = AS3::local::internal::_null;
    25.     AS3::local::var output = AS3::local::internal::call(myFun, rcv, 2, nums);
    26.    
    27.     // show the return value
    28.     char* resultString = AS3::local::internal::utf8_toString(output);
    29.     printf("result=%s\n", resultString); // output: result=hello
    30.     free(resultString);
    31. }
    复制代码
    Also see the 10_MessageChannel sample
    getproperty

    1. var getproperty(var obj, var name);
    复制代码
    Gets a property from an object referenced via the specified name in the public namespace.
    1. var getproperty(var obj, var ns, var name);
    复制代码
    Gets a property from an object referenced via the specified name and namespace.
    Parameters:
    • obj - object containing the property to be retrieved.
    • ns - var containing the namespace of the property to be retrieved.
    • name - var containing the name of the property to be retrieved.
    Example Usage:
    1. #include <Flash++.h>
    2. #include <stdio.h>

    3. using namespace AS3::local;

    4. int main() {
    5.     Date myDate = Date::_new();
    6.     AS3::local::var propertyName = AS3::local::internal::new_String("fullYear");
    7.     AS3::local::var propertyValue = AS3::local::internal::getproperty(myDate, propertyName);
    8.    
    9.     std::string str = AS3::sz2stringAndFree(internal::utf8_toString(propertyValue));
    10.     printf("fullYear=%s\n", str.c_str()); // output: fullYear=2012
    11. }
    复制代码
    setproperty

    1. void setproperty(var obj, var name, var val);
    复制代码
    Sets a property on an object referenced via the specified name in the public namespace.
    1. void setproperty(var obj, var ns, var name, var val);
    复制代码
    Sets a property on an object referenced via the specified name and namespace.
    Parameters:
    • obj - object containing the property to be set.
    • ns - var containing the namespace of the property to be set.
    • name - var containing the name of the property to be set.
    • val - var containing the value to be applied to name.
    Example Usage:
    1. #include <Flash++.h>
    2. #include <stdio.h>

    3. using namespace AS3::local;

    4. int main() {
    5.     Date myDate = Date::_new();
    6.     AS3::local::var propertyName = AS3::local::internal::new_String("fullYear");
    7.     AS3::local::var newValue = AS3::local::internal::new_int(1999);
    8.    
    9.     // change the year
    10.     AS3::local::internal::setproperty(myDate, propertyName, newValue);
    11.    
    12.     std::string str = AS3::sz2stringAndFree(internal::utf8_toString(myDate));
    13.     printf("myDate=%s\n", str.c_str()); // output: myDate=Wed Nov 10...1999
    14. }
    复制代码
    getlex

    1. var getlex(var name);
    复制代码
    Gets a property from the current global object.
    1. var getlex(var ns, var name);
    复制代码
    Gets a property from the current global object in the specified namespace.
    Parameters:
    • ns - var containing the namespace.
    • name - var containing the name of the property to be retrieved.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <Flash++.h>
    3. #include <stdio.h>

    4. using namespace AS3::local;

    5. int main() {
    6.     // create a class closure that represents the flash.events.MouseEvent class
    7.     AS3::local::var ns = AS3::local::internal::new_Namespace("flash.events", 12);
    8.     AS3::local::var className = AS3::local::internal::new_String("MouseEvent");
    9.     AS3::local::var cc = AS3::local::internal::getlex(ns, className);

    10.     // Tip: Another way of getting a class closure is to use the internal::getClosure()
    11.     // function of Flash++ classes:
    12.     //
    13.     // Class cc = flash::events::MouseEvent::internal::getClosure();

    14.     // construct a MouseEvent object
    15.     AS3::local::var arg1 = AS3::local::internal::new_String("mouseDown");
    16.     AS3::local::var event = AS3::local::internal::construct(cc, arg1);
    17.    
    18.     char* strEvent = AS3::local::internal::utf8_toString(event);
    19.     printf("event=%s\n", strEvent); // output: event=[MouseEvent ...
    20.     free(strEvent);
    21. }
    复制代码
    setlex

    1. void setlex(var name, var val);
    复制代码
    Sets a property on the current global object.
    1. void setlex(var ns, var name, var val);
    复制代码
    Sets a property on the current global object in the specified namespace.
    Parameters:
    • ns - var containing the namespace.
    • name - var containing the name of the property to be set.
    • val - var containing the value to be applied to name.
    construct

    1. var construct(var cc);
    复制代码
    1. var construct(var cc, var a1);
    复制代码
    1. var construct(var cc, var a1, var a2);
    复制代码
    1. var construct(var cc, var a1, var a2, var a3);
    复制代码
    1. var construct(var cc, var a1, var a2, var a3, var a4);
    复制代码
    1. var construct(var cc, var a1, var a2, var a3, var a4, var a5);
    复制代码
    Constructs an object of type cc.
    Parameters:
    • cc - var specifying the class to be constructed.
    • a1 through a5 - vars containing up to five parameters passed to the constructor.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <Flash++.h>
    3. #include <stdio.h>

    4. using namespace AS3::local;

    5. int main() {
    6.     // create a class closure that represents the MouseEvent class
    7.     AS3::local::var ns = AS3::local::internal::new_Namespace("flash.events", 12);
    8.     AS3::local::var className = AS3::local::internal::new_String("MouseEvent");
    9.     AS3::local::var cc = AS3::local::internal::getlex(ns, className);
    10.    
    11.     // construct a MouseEvent object
    12.     AS3::local::var arg1 = AS3::local::internal::new_String("mouseDown");
    13.     AS3::local::var event = AS3::local::internal::construct(cc, arg1);
    14.    
    15.     char* strEvent = AS3::local::internal::utf8_toString(event);
    16.     printf("event=%s\n", strEvent); // output: event=[MouseEvent ...
    17.     free(strEvent);
    18. }
    复制代码
    coerce

    1. var coerce(var cc, var v);
    复制代码
    Coerce an object v to type cc. This differs slightly from the as function because it throws an error when v cannot be coerced into cc whereas the as function does not throw an error and instead returns _null. See the AS3 type conversions documentation for more details.
    Parameters:
    • cc - var containing a class closure for the target type.
    • v - var containing the object to be coerced.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var n = AS3::local::internal::new_int(5);
    5.    
    6.     // create a class closure that represents the String class
    7.     AS3::local::var className = AS3::local::internal::new_String("String");
    8.     AS3::local::var cc = AS3::local::internal::getlex(className);
    9.    
    10.     // coerce an int to a String
    11.     AS3::local::var output = AS3::local::internal::coerce(cc, n);
    12.    
    13.     char* strOutput = AS3::local::internal::utf8_toString(output);
    14.     char* strType = AS3::local::internal::utf8_toString(AS3::local::internal::_typeof(output));
    15.     printf("type=%s, value=%s\n", strType, strOutput); // output: type=string, value=5
    16.     free(strOutput);
    17.     free(strType);
    18. }
    复制代码
    _delete

    1. bool _delete(var obj, var prop);
    复制代码
    Equivalent to the AS3 delete operator. Returns true if the deletion succeeded.
    Parameters:
    • obj - var containing the Object to delete the property from.
    • prop - var containing the name of the property to be deleted.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <Flash++.h>
    3. #include <stdio.h>

    4. using namespace AS3::local;

    5. int main() {
    6.     // create an object with a first name property
    7.     Object o = Object::_new();
    8.     o["firstName"] = AS3::local::internal::new_String("Mike");
    9.    
    10.     // show the value of that property
    11.     char* outputString = internal::utf8_toString(o["firstName"]);
    12.     printf("firstName=%s\n", outputString);  // output: firstName=Mike
    13.     free(outputString);
    14.    
    15.     // delete that property
    16.     AS3::local::internal::_delete(o, AS3::local::internal::new_String("firstName"));
    17.    
    18.     // show that the firstName property no longer exists
    19.     outputString = internal::utf8_toString(o["firstName"]);
    20.     printf("firstName=%s\n", outputString); // output: firstName=undefined
    21.     free(outputString);
    22. }
    复制代码
    _throw

    1. void _throw(var val);
    复制代码
    Throws the var as an AS3 exception.
    Parameters:
    • val - var to be thrown as an AS3 exception.
    Example Usage:
    1. #include <Flash++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::Error e = AS3::local::Error::_new();
    5.     e->message = AS3::local::internal::new_String("My Error");
    6.    
    7.     AS3::local::internal::_throw(e);
    8. }
    复制代码
    utf8_toString

    1. char* utf8_toString(var val);
    复制代码
    Calls toString() on the AS3 object and copies the string into a malloc'ed buffer. You are responsible for freeing the returned string.
    Parameters:
    • val - var containing the AS3 object to be converted to a string.
    Example Usage:
    1. #include <Flash++.h>
    2. #include <stdio.h>

    3. using namespace AS3::local;

    4. int main() {
    5.     Date myDate = Date::_new();
    6.     char* str = internal::utf8_toString(myDate);
    7.     printf("%s\n",str); // output: Sat Nov 10 10:14:26 GMT-0800 2012
    8.     free(str);
    9. }
    复制代码
    bool_valueOf

    1. bool bool_valueOf(var val);
    复制代码
    Cast the var to a boolean.
    Parameters:
    • val - var to be cast to boolean.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_String("3.1415");
    5.     bool b = AS3::local::internal::bool_valueOf(x);
    6.    
    7.     if (b)
    8.         printf("b == true"); // output: b == true
    9. }
    复制代码
    int_valueOf

    1. int int_valueOf(var val);
    复制代码
    Cast the var to an int.
    Parameters:
    • val - var to be cast to int.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_String("3.1415");
    5.     int i = AS3::local::internal::int_valueOf(x);
    6.    
    7.     printf("i=%d\n", i); // output: i=3
    8. }
    复制代码
    uns_valueOf

    1. unsigned uns_valueOf(var val);
    复制代码
    Cast the var to an unsigned int.
    Parameters:
    • val - var to be cast to unsigned int.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_String("3.1415");
    5.     unsigned u = AS3::local::internal::uns_valueOf(x);
    6.    
    7.     printf("u=%d\n", u); // output: u=3
    8. }
    复制代码
    double_valueOf

    1. double double_valueOf(var val);
    复制代码
    Cast the var to a double.
    Parameters:
    • val - var to be cast to double.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var x = AS3::local::internal::new_String("3.1415");
    5.     double d = AS3::local::internal::double_valueOf(x);
    6.    
    7.     printf("d=%f\n", d); // output: d=3.1415
    8. }
    复制代码
    is

    1. bool is(var a, var b);
    复制代码
    Equivalent to the AS3 is operator. Returns true when a is compatible with a specific data type, class, or interface b. Use the is operator instead of the instanceof operator for type comparisons. You can also use the is operator to check whether an object implements an interface.
    Parameters:
    • a - var containing a data type, class, or interface.
    • b - var containing a data type, class, or interface.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var s = AS3::local::internal::new_String("hello");
    5.     AS3::local::var n = AS3::local::internal::new_int(5);
    6.    
    7.     // create a class closure that represents the String class
    8.     AS3::local::var className = AS3::local::internal::new_String("String");
    9.     AS3::local::var cc = AS3::local::internal::getlex(className);
    10.         
    11.     if (AS3::local::internal::is(s, cc))
    12.         printf("s is a String"); // output: s is a String
    13.     else
    14.         printf("s is not a String");
    15.    
    16.     if (AS3::local::internal::is(n, cc))
    17.         printf("n is a String");
    18.     else
    19.         printf("n is not a String"); // output: n is not a String
    20.    
    21. }
    复制代码
    as

    1. var as(var a, var b);
    复制代码
    Equivalent to the AS3 as operator. Returns a casted to b or _null if a cannot be casted to b.
    Parameters:
    • a - var containing the value to check against the data type specified by b.
    • b - var containing the data type used to evaluate a.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var s = AS3::local::internal::new_String("hello");
    5.     AS3::local::var n = AS3::local::internal::new_int(5);
    6.    
    7.     // create a class closure that represents the String class
    8.     AS3::local::var className = AS3::local::internal::new_String("String");
    9.     AS3::local::var cc = AS3::local::internal::getlex(className);
    10.    
    11.     // cast using as
    12.     AS3::local::var sAsString = AS3::local::internal::as(s, cc);
    13.     AS3::local::var nAsString = AS3::local::internal::as(n, cc);

    14.     if (sAsString != AS3::local::internal::_null)
    15.         printf("s was successfully casted to a String\n"); // output: s was...
    16.    
    17.     if (nAsString == AS3::local::internal::_null)
    18.         printf("n could not be casted to a String\n"); // output: n could not...
    19. }
    复制代码
    instanceof

    1. bool instanceof(var a, var b);
    复制代码
    Equivalent to the AS3 instanceof operator. Returns whether a is a property of the object represented by b.         To check whether an object is a member of a specific data type, use the is operator. The instanceof operator always returns false with interfaces, whereas the is operator results in true if an object belongs to a class that implements the specified interface.
    Parameters:
    • a - var containing the object that contains the prototype chain to evaluate.
    • b - var containing a function object (or class).
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var s = AS3::local::internal::new_String("hello");
    5.     AS3::local::var n = AS3::local::internal::new_int(5);
    6.    
    7.     // create a class closure that represents the String class
    8.     AS3::local::var className = AS3::local::internal::new_String("String");
    9.     AS3::local::var cc = AS3::local::internal::getlex(className);
    10.    
    11.     if (AS3::local::internal::instanceof(s, cc))
    12.         printf("s is an instance of String\n"); // output: s is ...
    13.    
    14.     if (!AS3::local::internal::instanceof(n, cc))
    15.         printf("n is not an instance of String\n"); // output: n is not ...
    16. }
    复制代码
    in

    1. bool in(var a, var b);
    复制代码
    Equivalent to the AS3 in operator. Returns true if a is a member of the data type specified by b.
    Parameters:
    • a - var containing a property name.
    • b - var containing a data type or instance.
    Example Usage:
    1. #include <AS3/AS3++.h>
    2. #include <stdio.h>

    3. int main() {
    4.     AS3::local::var property = AS3::local::internal::new_String("length");
    5.     AS3::local::var myString = AS3::local::internal::new_String("hello");
    6.    
    7.     bool x = AS3::local::internal::in(property, myString);
    8.    
    9.     if (x)
    10.         printf("var myString has a length property"); // output: var myString...
    11. }
    复制代码
    trace

    1. void trace(var val);
    复制代码
    Trace a var to the Flash log file, if enabled.
    Parameters:
    • val - var to be written to the Flash log file.
    Example Usage:
    1. #include <AS3/AS3++.h>

    2. int main() {
    3.     AS3::local::var s = AS3::local::internal::new_String("Hello World");
    4.     AS3::local::internal::trace(s);
    5. }
    复制代码

    Namespace:AS3::ui::internal

    FunctionDescription
    get_Stage

    1. var get_Stage();
    复制代码
    Get a reference to the Flash Stage object.
    Example Usage:
    1. #include <stdio.h>
    2. #include <Flash++.h>

    3. using namespace AS3::ui;

    4. int main()
    5. {
    6.     flash::display::Stage stage = AS3::ui::internal::get_Stage();
    7.    
    8.     flash::display::Sprite mySprite = flash::display::Sprite::_new();
    9.     flash::display::Graphics graphics = mySprite->graphics;
    10.     graphics->beginFill(0x0000ff, 1.0);
    11.     graphics->drawCircle(50.0, 50.0, 50.0);
    12.     graphics->endFill();
    13.    
    14.     stage->addChild(mySprite);
    15. }
    复制代码


    相关链接:







    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
    收藏收藏1 分享分享 支持支持1 反对反对 微信
    守望者AIR技术交流社区(www.airmyth.com)
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2018-4-10 15:18
  • 签到天数: 447 天

    [LV.9]以坛为家II

    1742

    主题

    2094

    帖子

    13万

    积分

    超级版主

    Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

    威望
    562
    贡献
    29
    金币
    52694
    钢镚
    1422

    开源英雄守望者

    沙发
     楼主| 发表于 2014-12-29 23:58:14 | 只看该作者
    谁有能力翻译一下
    守望者AIR技术交流社区(www.airmyth.com)
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    郁闷
    2016-8-19 16:08
  • 签到天数: 7 天

    [LV.3]偶尔看看II

    4

    主题

    31

    帖子

    2628

    积分

    少尉

    Rank: 6Rank: 6

    威望
    0
    贡献
    8
    金币
    320
    钢镚
    25
    板凳
    发表于 2015-1-11 14:55:07 | 只看该作者
    竟然有文档
    我是一个兵
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    
    关闭

    站长推荐上一条 /4 下一条

    QQ|手机版|Archiver|网站地图|小黑屋|守望者 ( 京ICP备14061876号

    GMT+8, 2024-4-20 06:55 , Processed in 0.070844 second(s), 29 queries .

    守望者AIR

    守望者AIR技术交流社区

    本站成立于 2014年12月31日

    快速回复 返回顶部 返回列表