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.

AS3++.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:

/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:

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

using namespace AS3::local;

int main(){
    Date myDate = Date::_new();

    printf("%d\n", myDate->fullYear); // output: 7
}

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

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

using namespace AS3::local;

int main(){
    Date myDate = Date::_new();

    int year = AS3::local::internal::int_valueOf(myDate->fullYear);
    printf("%d\n", year); // output: 2012
}

 

Namespace: AS3

Function Description

sz2stringAndFree

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:

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

using namespace AS3::local;

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

 

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.

Function Description

new_int

var new_int(int n);

Create an AS3 int object.

Parameters:

  • n - int value.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_int(5);
    
    // show the type and value of that var
    char* type = AS3::local::internal::utf8_toString(AS3::local::internal::_typeof(x));
    int value = AS3::local::internal::int_valueOf(x);
    printf("type: %s, value: %d\n", type, value); // output: type: number, value: 5
    free(type);
}

Also see the 10_MessageChannel sample

new_uint

var new_uint(unsigned n);

Create an AS3 uint object.

Parameters:

  • n - unsigned integer value.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_uint(5);
    
    // show the type and value of that var
    char* type = AS3::local::internal::utf8_toString(AS3::local::internal::_typeof(x));
    unsigned value = AS3::local::internal::uns_valueOf(x);
    printf("type: %s, value: %d\n", type, value); // output: type: number, value: 5
    free(type);
}

new_Number

var new_Number(double n);

Create an AS3 Number object.

Parameters:

  • n - double value.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_Number(5.5);
    
    // show the type and value of that var
    char* type = AS3::local::internal::utf8_toString(AS3::local::internal::_typeof(x));
    double value = AS3::local::internal::double_valueOf(x);
    printf("type: %s, value: %f\n", type, value); // output: type: number, value: 5.500000
    free(type);
}

Also see the 12_Stage3D sample

new_Boolean

var new_Boolean(bool b);

Create an AS3 Boolean object.

Parameters:

  • b - boolean value.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_Boolean(true);
    
    bool value = AS3::local::internal::bool_valueOf(x);
    
    if (value)
        printf("x == true"); // output: x == true
}

new_String

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:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_String("hello");
    
    char* str = AS3::local::internal::utf8_toString(x);
    printf("%s\n", str); // output: hello
    free(str);
}

Also see the 10_MessageChannel sample

new_Namespace

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:

#include <AS3/AS3++.h>
#include <Flash++.h>
#include <stdio.h>

using namespace AS3::local;

int main() {
    // create a class closure that represents the MouseEvent class
    AS3::local::var ns = AS3::local::internal::new_Namespace("flash.events", 12);
    AS3::local::var className = AS3::local::internal::new_String("MouseEvent");
    AS3::local::var cc = AS3::local::internal::getlex(ns, className);
    
    // construct a MouseEvent object
    AS3::local::var arg1 = AS3::local::internal::new_String("mouseDown");
    AS3::local::var event = AS3::local::internal::construct(cc, arg1);
    
    char* strEvent = AS3::local::internal::utf8_toString(event);
    printf("event=%s\n", strEvent); // output: event=[MouseEvent type="mouseDown" ...
    free(strEvent);
}

new_Array

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:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x1 = AS3::local::internal::new_int(5);
    AS3::local::var x2 = AS3::local::internal::new_int(6);
    AS3::local::var nums[2] = {x1, x2};
    AS3::local::var myArray = AS3::local::internal::new_Array(2, nums);
    
    char* str = AS3::local::internal::utf8_toString(myArray);
    printf("myArray=%s\n", str); // output: myArray=5,6
    free(str);
}

new_Function

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:

#include <AS3/AS3++.h>
#include <stdio.h>

AS3::local::var square(void *arg, AS3::local::var as3Args) {
    // C argument
    int x = (int) arg;
    
    // AS3 arguments
    AS3::local::var test1 = as3Args[0];
    AS3::local::var test2 = as3Args[1];
    
    printf("C arg: %d\n", x); // output: C arg: 5
    
    printf("as3Args: %d, %d\n", 
           AS3::local::internal::int_valueOf(test1), 
           AS3::local::internal::int_valueOf(test2)); // output: as3Args: 5, 6
    
    return AS3::local::internal::new_String("hello");
}

int main() {
    // create some AS3 arguments to pass to the function
    AS3::local::var x1 = AS3::local::internal::new_int(5);
    AS3::local::var x2 = AS3::local::internal::new_int(6);
    AS3::local::var nums[2] = {x1, x2};
    AS3::local::var argsArray = AS3::local::internal::new_Array(2, nums);
    
    // create the Function var
    AS3::local::var myFun = AS3::local::internal::new_Function(square, (void*) 5);    
    
    // call the Function
    AS3::local::var rcv = AS3::local::internal::_null;
    AS3::local::var res = AS3::local::internal::call_v(myFun, rcv, argsArray);
    
    // show the return value
    char* resultString = AS3::local::internal::utf8_toString(res);
    printf("result=%s\n", resultString); // output: result=hello
    free(resultString);
}

Also see the 10_MessageChannel sample and the handling mouse input Flash++ example.

new_Vector

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:

#include <AS3/AS3++.h>
#include <Flash++.h>
#include <stdio.h>

using namespace AS3::local;

int main() {
    // create a class closure that represents the MouseEvent class
    AS3::local::var ns = AS3::local::internal::new_Namespace("flash.events", 12);
    AS3::local::var className = AS3::local::internal::new_String("MouseEvent");
    AS3::local::var cc = AS3::local::internal::getlex(ns, className);
    
    // create a Vector of MouseEvents
    AS3::local::var v = AS3::local::internal::new_Vector(cc);
    v[0] = flash::events::MouseEvent::_new(AS3::local::internal::new_String("mouseDown"));
    v[1] = flash::events::MouseEvent::_new(AS3::local::internal::new_String("mouseUp"));
    v[2] = flash::events::MouseEvent::_new(AS3::local::internal::new_String("mouseClick"));
    
    char* vStr = AS3::local::internal::utf8_toString(v);
    printf("v=%s\n", vStr); // output: v=[MouseEvent type="mouseDown" ...
    free(vStr);
}

new_Vector_int

var new_Vector_int();

Create an AS3 Vector of type int.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var v = AS3::local::internal::new_Vector_int();
    v[0] = AS3::local::internal::new_int(0);
    v[1] = AS3::local::internal::new_int(1);
    v[2] = AS3::local::internal::new_int(2);
    
    char* vStr = AS3::local::internal::utf8_toString(v);
    printf("v=%s\n", vStr); // output: v=0,1,2
    free(vStr);
}

new_Vector_uint

var new_Vector_uint();

Create an AS3 Vector of type uint.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    // create a Vector of uints
    AS3::local::var v = AS3::local::internal::new_Vector_uint();
    v[0] = AS3::local::internal::new_uint(0);
    v[1] = AS3::local::internal::new_uint(1);
    v[2] = AS3::local::internal::new_uint(2);
    
    char* vStr = AS3::local::internal::utf8_toString(v);
    printf("v=%s\n", vStr); // output: v=0,1,2
    free(vStr);
}

new_Vector_Boolean

var new_Vector_Boolean();

Create an AS3 Vector of type Boolean.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    // create a Vector of Booleans
    AS3::local::var v = AS3::local::internal::new_Vector_Boolean();
    v[0] = AS3::local::internal::_true;
    v[1] = AS3::local::internal::_false;
    v[2] = AS3::local::internal::_true;
    
    char* vStr = AS3::local::internal::utf8_toString(v);
    printf("v=%s\n", vStr); // output: v=true,false,true
    free(vStr);
}

new_Vector_String

var new_Vector_String();

Create an AS3 Vector of type String.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    // create a Vector of Strings
    AS3::local::var v = AS3::local::internal::new_Vector_String();
    v[0] = AS3::local::internal::new_String("a");
    v[1] = AS3::local::internal::new_String("b");
    v[2] = AS3::local::internal::new_String("c");
    
    char* vStr = AS3::local::internal::utf8_toString(v);
    printf("v=%s\n", vStr); // output: v=a,b,c
    free(vStr);
}

new_Vector_Number

var new_Vector_Number();

Create an AS3 Vector of type Number.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    // create a Vector of Numbers
AS3::local::var v = AS3::local::internal::new_Vector_Number();
v[0] = AS3::local::internal::new_Number(1.1);
v[1] = AS3::local::internal::new_Number(2.2);
v[2] = AS3::local::internal::new_Number(3.3);

char* vStr = AS3::local::internal::utf8_toString(v);
printf("v=%s\n", vStr); // output: v=1.1,2.2,3.3
free(vStr); }

Also see the 12_Stage3D sample

new_undefined

var new_undefined();

Create an AS3 undefined object. See _undefined.

new_null

var new_null();

Create an AS3 null object. See _null.

template <typename T> T new_null()

Create an AS3 null object of type T. See _null.

get_Worker

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

var get_ram();

Get a reference to the currently assigned domainMemory ByteArray.

Example Usage:

See the 10_MessageChannel sample

_undefined

extern const var _undefined;

The AS3 undefined var.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

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

int main() {
    // create the Function var
    AS3::local::var myFun = AS3::local::internal::new_Function(goodValue, NULL);    
    
    // create the arguments to pass to the function
    AS3::local::var arg1 = AS3::local::internal::new_int(0);
    AS3::local::var args[1] = {arg1};
    
    // call the Function
    AS3::local::var rcv = AS3::local::internal::_null;
    AS3::local::var output = AS3::local::internal::call(myFun, rcv, 1, args);
    
    // show the return value
    char* resultString = AS3::local::internal::utf8_toString(output);
    printf("result=%s\n", resultString); // output: result=undefined 
    free(resultString);
}

Also see the 12_Stage3D sample

_null

extern const var _null;

The AS3 null var.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

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

int main() {
    // create the Function var
    AS3::local::var myFun = AS3::local::internal::new_Function(goodValue, NULL);    
    
    // create the arguments to pass to the function
    AS3::local::var arg1 = AS3::local::internal::new_int(0);
    AS3::local::var args[1] = {arg1};
    
    // call the Function
    AS3::local::var rcv = AS3::local::internal::_null;
    AS3::local::var output = AS3::local::internal::call(myFun, rcv, 1, args);
    
    // show the return value
    char* resultString = AS3::local::internal::utf8_toString(output);
    printf("result=%s\n", resultString); // output: result=null
    free(resultString);
}

Also see the 09_Pthreads sample

_true

extern const var _true;

The AS3 true var.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

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

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

    // show the value
    if (AS3::local::internal::bool_valueOf(x))
        printf("x == true"); // output: x == true
    else
        printf("x == false");
}

_false

extern const var _false;

The AS3 false var.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

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

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

    // show the value
    if (AS3::local::internal::bool_valueOf(x))
        printf("x == true");
    else
        printf("x == false"); // output: x == false
}

_typeof

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:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var myObject = AS3::local::internal::new_String("Hello");
    AS3::local::var myObjectType = AS3::local::internal::_typeof(myObject);
    
    char* str = AS3::local::internal::utf8_toString(myObjectType);
    printf("type=%s\n",str); // output: type=string
    free(str);
}

equals

bool equals(var a, var b);

Equivalent to the AS3 equality operator "==".

Other similar functions include:

  • bool strictequals(var a, var b);
  • bool lessthan(var a, var b);
  • bool lessequals(var a, var b);
  • bool greaterthan(var a, var b);
  • bool greaterequals(var a, var b);

Parameters:

  • a - var containing an AS3 object.
  • b - var containing an AS3 object.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var e1 = AS3::local::internal::new_String("5");
    AS3::local::var e2 = AS3::local::internal::new_Number(5);
    
    bool equal = AS3::local::internal::equals(e1, e2);
    bool strictEqual = AS3::local::internal::strictequals(e1, e2);
    
    if (equal)
        printf("e1 == e2"); // output: e1 == e2
    if (strictEqual)
        printf("e1 === e2");
}

call_v

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:

#include <AS3/AS3++.h>
#include <stdio.h>

AS3::local::var square(void *arg, AS3::local::var as3Args) {
    // AS3 arguments
    AS3::local::var test1 = as3Args[0];
    AS3::local::var test2 = as3Args[1];
    
    printf("as3Args=%d, %d\n", 
           AS3::local::internal::int_valueOf(test1), 
           AS3::local::internal::int_valueOf(test2)); // output: as3args=5, 6
    
    return AS3::local::internal::new_String("hello");
}

int main() {
    // create some AS3 arguments to pass to the function
    AS3::local::var x1 = AS3::local::internal::new_int(5);
    AS3::local::var x2 = AS3::local::internal::new_int(6);
    AS3::local::var nums[2] = {x1, x2};
    AS3::local::var argsArray = AS3::local::internal::new_Array(2, nums);
    
    // create the Function var
    AS3::local::var myFun = AS3::local::internal::new_Function(square, NULL);    
    
    // call the Function
    AS3::local::var rcv = AS3::local::internal::_null;
    AS3::local::var output = AS3::local::internal::call_v(myFun, rcv, argsArray);
    
    // show the return value
    char* resultString = AS3::local::internal::utf8_toString(output);
    printf("result=%s\n", resultString); // output: result=hello
    free(resultString);
}

call

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:

#include <AS3/AS3++.h>
#include <stdio.h>

AS3::local::var square(void *arg, AS3::local::var as3Args) {
    // AS3 arguments
    AS3::local::var test1 = as3Args[0];
    AS3::local::var test2 = as3Args[1];
    
    printf("as3Args=%d, %d\n", 
           AS3::local::internal::int_valueOf(test1), 
           AS3::local::internal::int_valueOf(test2)); // output: as3Args=5,6
    
    return AS3::local::internal::new_String("hello");
}

int main() {
    // create some AS3 arguments to pass to the function
    AS3::local::var x1 = AS3::local::internal::new_int(5);
    AS3::local::var x2 = AS3::local::internal::new_int(6);
    AS3::local::var nums[2] = {x1, x2};
    
    // create the Function var
    AS3::local::var myFun = AS3::local::internal::new_Function(square, NULL);    
    
    // call the Function
    AS3::local::var rcv = AS3::local::internal::_null;
    AS3::local::var output = AS3::local::internal::call(myFun, rcv, 2, nums);
    
    // show the return value
    char* resultString = AS3::local::internal::utf8_toString(output);
    printf("result=%s\n", resultString); // output: result=hello
    free(resultString);
}

Also see the 10_MessageChannel sample

getproperty

var getproperty(var obj, var name);

Gets a property from an object referenced via the specified name in the public namespace.

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:

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

using namespace AS3::local;

int main() {
    Date myDate = Date::_new();
    AS3::local::var propertyName = AS3::local::internal::new_String("fullYear");
    AS3::local::var propertyValue = AS3::local::internal::getproperty(myDate, propertyName);
    
    std::string str = AS3::sz2stringAndFree(internal::utf8_toString(propertyValue));
    printf("fullYear=%s\n", str.c_str()); // output: fullYear=2012
}

setproperty

void setproperty(var obj, var name, var val);

Sets a property on an object referenced via the specified name in the public namespace.

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:

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

using namespace AS3::local;

int main() {
    Date myDate = Date::_new();
    AS3::local::var propertyName = AS3::local::internal::new_String("fullYear");
    AS3::local::var newValue = AS3::local::internal::new_int(1999);
    
    // change the year
    AS3::local::internal::setproperty(myDate, propertyName, newValue);
    
    std::string str = AS3::sz2stringAndFree(internal::utf8_toString(myDate));
    printf("myDate=%s\n", str.c_str()); // output: myDate=Wed Nov 10...1999
}

getlex

var getlex(var name);

Gets a property from the current global object.

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:

#include <AS3/AS3++.h>
#include <Flash++.h>
#include <stdio.h>

using namespace AS3::local;

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

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

    // construct a MouseEvent object
    AS3::local::var arg1 = AS3::local::internal::new_String("mouseDown");
    AS3::local::var event = AS3::local::internal::construct(cc, arg1);
    
    char* strEvent = AS3::local::internal::utf8_toString(event);
    printf("event=%s\n", strEvent); // output: event=[MouseEvent ...
    free(strEvent);
}

setlex

void setlex(var name, var val);

Sets a property on the current global object.

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

var construct(var cc);

var construct(var cc, var a1);

var construct(var cc, var a1, var a2);

var construct(var cc, var a1, var a2, var a3);

var construct(var cc, var a1, var a2, var a3, var a4);

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:

#include <AS3/AS3++.h>
#include <Flash++.h>
#include <stdio.h>

using namespace AS3::local;

int main() {
    // create a class closure that represents the MouseEvent class
    AS3::local::var ns = AS3::local::internal::new_Namespace("flash.events", 12);
    AS3::local::var className = AS3::local::internal::new_String("MouseEvent");
    AS3::local::var cc = AS3::local::internal::getlex(ns, className);
    
    // construct a MouseEvent object
    AS3::local::var arg1 = AS3::local::internal::new_String("mouseDown");
    AS3::local::var event = AS3::local::internal::construct(cc, arg1);
    
    char* strEvent = AS3::local::internal::utf8_toString(event);
    printf("event=%s\n", strEvent); // output: event=[MouseEvent ...
    free(strEvent);
}

coerce

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:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var n = AS3::local::internal::new_int(5);
    
    // create a class closure that represents the String class
    AS3::local::var className = AS3::local::internal::new_String("String");
    AS3::local::var cc = AS3::local::internal::getlex(className);
    
    // coerce an int to a String
    AS3::local::var output = AS3::local::internal::coerce(cc, n);
    
    char* strOutput = AS3::local::internal::utf8_toString(output);
    char* strType = AS3::local::internal::utf8_toString(AS3::local::internal::_typeof(output));
    printf("type=%s, value=%s\n", strType, strOutput); // output: type=string, value=5
    free(strOutput);
    free(strType);
}

_delete

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:

#include <AS3/AS3++.h>
#include <Flash++.h>
#include <stdio.h>

using namespace AS3::local;

int main() {
    // create an object with a first name property
    Object o = Object::_new();
    o["firstName"] = AS3::local::internal::new_String("Mike");
    
    // show the value of that property
    char* outputString = internal::utf8_toString(o["firstName"]);
    printf("firstName=%s\n", outputString);  // output: firstName=Mike
    free(outputString);
    
    // delete that property
    AS3::local::internal::_delete(o, AS3::local::internal::new_String("firstName"));
    
    // show that the firstName property no longer exists
    outputString = internal::utf8_toString(o["firstName"]);
    printf("firstName=%s\n", outputString); // output: firstName=undefined
    free(outputString);
}

_throw

void _throw(var val);

Throws the var as an AS3 exception.

Parameters:

  • val - var to be thrown as an AS3 exception.

Example Usage:

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

int main() {
    AS3::local::Error e = AS3::local::Error::_new();
    e->message = AS3::local::internal::new_String("My Error");
    
    AS3::local::internal::_throw(e);
}

utf8_toString

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:

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

using namespace AS3::local;

int main() {
    Date myDate = Date::_new();
    char* str = internal::utf8_toString(myDate);
printf("%s\n",str); // output: Sat Nov 10 10:14:26 GMT-0800 2012 free(str); }

bool_valueOf

bool bool_valueOf(var val);

Cast the var to a boolean.

Parameters:

  • val - var to be cast to boolean.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_String("3.1415");
    bool b = AS3::local::internal::bool_valueOf(x);
    
    if (b)
        printf("b == true"); // output: b == true
}

int_valueOf

int int_valueOf(var val);

Cast the var to an int.

Parameters:

  • val - var to be cast to int.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_String("3.1415");
    int i = AS3::local::internal::int_valueOf(x);
    
    printf("i=%d\n", i); // output: i=3
}

uns_valueOf

unsigned uns_valueOf(var val);

Cast the var to an unsigned int.

Parameters:

  • val - var to be cast to unsigned int.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_String("3.1415");
    unsigned u = AS3::local::internal::uns_valueOf(x);
    
    printf("u=%d\n", u); // output: u=3
}

double_valueOf

double double_valueOf(var val);

Cast the var to a double.

Parameters:

  • val - var to be cast to double.

Example Usage:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var x = AS3::local::internal::new_String("3.1415");
    double d = AS3::local::internal::double_valueOf(x);
    
    printf("d=%f\n", d); // output: d=3.1415
}

is

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:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var s = AS3::local::internal::new_String("hello");
    AS3::local::var n = AS3::local::internal::new_int(5);
    
    // create a class closure that represents the String class
    AS3::local::var className = AS3::local::internal::new_String("String");
    AS3::local::var cc = AS3::local::internal::getlex(className);
        
    if (AS3::local::internal::is(s, cc))
        printf("s is a String"); // output: s is a String
    else
        printf("s is not a String");
    
    if (AS3::local::internal::is(n, cc))
        printf("n is a String");
    else
        printf("n is not a String"); // output: n is not a String
    
}

as

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:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var s = AS3::local::internal::new_String("hello");
    AS3::local::var n = AS3::local::internal::new_int(5);
    
    // create a class closure that represents the String class
    AS3::local::var className = AS3::local::internal::new_String("String");
    AS3::local::var cc = AS3::local::internal::getlex(className);
    
    // cast using as
    AS3::local::var sAsString = AS3::local::internal::as(s, cc);
    AS3::local::var nAsString = AS3::local::internal::as(n, cc);

    if (sAsString != AS3::local::internal::_null)
        printf("s was successfully casted to a String\n"); // output: s was...
    
    if (nAsString == AS3::local::internal::_null)
        printf("n could not be casted to a String\n"); // output: n could not...
}

instanceof

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:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var s = AS3::local::internal::new_String("hello");
    AS3::local::var n = AS3::local::internal::new_int(5);
    
    // create a class closure that represents the String class
    AS3::local::var className = AS3::local::internal::new_String("String");
    AS3::local::var cc = AS3::local::internal::getlex(className);
    
    if (AS3::local::internal::instanceof(s, cc))
        printf("s is an instance of String\n"); // output: s is ...
    
    if (!AS3::local::internal::instanceof(n, cc))
        printf("n is not an instance of String\n"); // output: n is not ...
}

in

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:

#include <AS3/AS3++.h>
#include <stdio.h>

int main() {
    AS3::local::var property = AS3::local::internal::new_String("length");
    AS3::local::var myString = AS3::local::internal::new_String("hello");
    
    bool x = AS3::local::internal::in(property, myString);
    
    if (x)
        printf("var myString has a length property"); // output: var myString...
}

trace

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:

#include <AS3/AS3++.h>

int main() {
    AS3::local::var s = AS3::local::internal::new_String("Hello World");
    AS3::local::internal::trace(s);
}

 

Namespace: AS3::ui::internal

Function Description

get_Stage

var get_Stage();

Get a reference to the Flash Stage object.

Example Usage:

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

using namespace AS3::ui;

int main()
{
    flash::display::Stage stage = AS3::ui::internal::get_Stage();
    
    flash::display::Sprite mySprite = flash::display::Sprite::_new();
    flash::display::Graphics graphics = mySprite->graphics;
    graphics->beginFill(0x0000ff, 1.0);
    graphics->drawCircle(50.0, 50.0, 50.0);
    graphics->endFill();
    
    stage->addChild(mySprite);
}