C/C++ API Reference
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:
/crossbridge/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 |
Turns a null-terminated char* into a std::string and frees the memory it used in the process. Parameters:
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 |
Create an AS3 int object. Parameters:
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 |
Create an AS3 uint object. Parameters:
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 |
Create an AS3 Number object. Parameters:
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 |
Create an AS3 Boolean object. Parameters:
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 |
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:
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 |
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:
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 |
Create an AS3 Array containing references to the specified AS3 vars. Parameters:
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 |
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:
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 |
Create an AS3 Vector.<cc>, where cc is a class closure. Parameters:
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 |
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 |
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 |
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 |
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 |
Create an AS3 Vector of type Number.
Example Usage: #include <AS3/AS3++.h> #include <stdio.h> int main() { // create a Vector of Numbers Also see the 12_Stage3D sample |
new_undefined |
Create an AS3 undefined object. See _undefined. |
new_null |
Create an AS3 null object. See _null.
|
get_Worker |
Get a reference to the Worker object for a given thread id. Parameters:
Example Usage: See the 10_MessageChannel sample |
get_ram |
Get a reference to the currently assigned domainMemory ByteArray. Example Usage: See the 10_MessageChannel sample |
_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 |
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 |
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 |
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 |
Equivalent to the AS3 typeof operator, which returns a String representation of the type of the AS3 object. Parameters:
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 |
Equivalent to the AS3 equality operator "==". Other similar functions include:
Parameters:
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 |
Use Function.apply to call a Function object with an Array of arguments. Parameters:
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 |
Use Function.apply to call a Function object with the arguments array constructed automatically. Parameters:
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 |
Gets a property from an object referenced via the specified name in the public namespace.
Gets a property from an object referenced via the specified name and namespace. Parameters:
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 |
Sets a property on an object referenced via the specified name in the public namespace.
Sets a property on an object referenced via the specified name and namespace. Parameters:
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 |
Gets a property from the current global object.
Gets a property from the current global object in the specified namespace. Parameters:
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 |
Sets a property on the current global object.
Sets a property on the current global object in the specified namespace. Parameters:
|
construct |
Constructs an object of type cc. Parameters:
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 |
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:
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 |
Equivalent to the AS3 delete operator. Returns true if the deletion succeeded. Parameters:
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 |
Throws the var as an AS3 exception. Parameters:
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 |
Calls toString() on the AS3 object and copies the string into a malloc'ed buffer. You are responsible for freeing the returned string. Parameters:
Example Usage: #include <Flash++.h> #include <stdio.h> using namespace AS3::local; int main() { Date myDate = Date::_new(); char* str = internal::utf8_toString(myDate); |
bool_valueOf |
Cast the var to a boolean. Parameters:
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 |
Cast the var to an int. Parameters:
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 |
Cast the var to an unsigned int. Parameters:
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 |
Cast the var to a double. Parameters:
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 |
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:
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 |
Equivalent to the AS3 as operator. Returns a casted to b or _null if a cannot be casted to b. Parameters:
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 |
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:
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 |
Equivalent to the AS3 in operator. Returns true if a is a member of the data type specified by b. Parameters:
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 |
Trace a var to the Flash log file, if enabled. Parameters:
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 |
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); } |