Table of contents [hide ] |
This API is declared in AS3.h found in $ALCHEMY_HOME/avm2_clib/include. In general where const char* is passed and no length is passed, the string is assumed to be NULL-terminated.
These functions can be used to create instances of various ActionScript types and manage references to them. You can always create objects directly using the namespace APIs as well.
This is the type Alchemy uses to represent ActionScript objects. Internals of the structure may change in later release.
This method increments the reference count for the ActionScript object. This impacts whether the runtime will collect this object when the GC is run next.
This method decrements the reference count for the ActionScript object. This impacts whether the runtime will collect this object when the GC is run next.
This method will call the ActionScript method constr passing the params value to it. The params value must be an ActionScript object of type Array. It may be empty if there are no parameters needed, but it should not be null. The return value is the newly constructed ActionScript object. To get the constructor method to use, you will need to query the appropriate namespace. See AS3_NSGet for a good example of this.
Get the ActionScript type for the passed object. The returned string must be free'd.
Compares the type of val against the class type passed in.
Returns 0 if val is not of type type . Returns non-zero otherwise.
Example:
AS3_Val ArrayClass = AS3_NSGetS(NULL, "Array"); if(!AS3_InstanceOf(AS3_Array(""), ArrayClass))) sztrace("whaaa!");
This method does a lookup in the runtime for the named property in the specified namespace.
The function returns whatever the runtime has defined as that property, typically a method. If the value is not found, NULL is returned.
Example:
AS3_Val flash_utils_namespace = AS3_String("flash.utils"); AS3_Val ByteArray_property = AS3_String("ByteArray"); AS3_Val ByteArray_class = AS3_NSGetS(flash_utils_namespace, ByteArray_property); AS3_Val byteArray = AS3_New(ByteArray_class, no_params); AS3_Release(ByteArray_class); AS3_Release(ByteArray_property); AS3_Release(flash_utils_namespace);
This method is the same as AS3_NSGet() but uses a const char* instead of an ActionScript String for the property name. The return value is the same.
Example:
AS3_Val flash_utils_namespace = AS3_String("flash.utils"); AS3_Val ByteArray_class = AS3_NSGetS(flash_utils_namespace, "ByteArray"); AS3_Val byteArray = AS3_New(ByteArray_class, no_params); AS3_Release(ByteArray_class); AS3_Release(flash_utils_namespace);
Returns a newly created ActionScript String object whose contents are copied from const char* value passed in. Null-termination is assumed. Must be released with AS3_Release().
Returns a newly created ActionScript String object whose contents are copied from first <len> bytes of the const char* value passed in. Must be released with AS3_Release().
Returns a newly created ActionScript int object that contains the value passed in. Must be released with AS3_Release().
Returns a newly created ActionScript uint whose value is the offset of this value from the beginning of the ByteArray being used as "ram". Must be released with AS3_Release().
Returns a newly created ActionScript Number object that contains the double passed in. Must be released with AS3_Release().
Returns a newly created ActionScript Boolean object set to true. Must be released with AS3_Release().
Returns a newly created ActionScript Boolean object set to false. Must be released with AS3_Release().
Returns a "null" reference to pass to ActionScript. This does not need to be released.
Returns an "undefined" reference to pass to ActionScript. This does not need to be released.
This method creates an ActionScript Array from a type template and list of parameters. tt is the type template and format looks like "type0, type1, type2". The types supported are:
The return value is the new Array containing the values passed. You will need to call AS3_Release() when you are done with it.
Example:
AS3_Val point = AS3_Array("IntType, IntType", x, y);
This method creates an ActionScript Object from a type template and list of parameters. tt is the type template and format looks like "name0:type0, name1:type1, name2:type2". The types supported are the same as for AS3_Array().
The return value is the new Object containing the values passed with the name specified. You will need to call AS3_Release() when you are done with it.
Example:
AS3_Val addr = AS3_Array("city:StrType, state:StrType, zip:StrType", "Anytown", "State", "12345");
Convert the ActionScript object passed to a char*. The returned value must be freed.
Convert the ActionScript object passed to an int.
Convert the ActionScript object passed to a void*.
Convert the ActionScript object passed to a double.
This function is used to extract values from the ActionScript Array arr according to the tt type template. The format of tt follows that of AS3_Array(). The parameters following tt should all be pointers to variables of the expected type. If the number of type entries in tt exceeds the number of elements in the Array, the additional variables are ignored. If the number of elements in the Array exceeds the number of entries in tt , the additional entries are ignored.
Example:
int arg0 = 0; char* arg1 = NULL; double arg2 = 0.0; AS3_ArrayValue(arr, "IntType, StrType, DoubleType", &arg0, &arg1, &arg2);
This function is used to extract values from the ActionScript Object obj according to the tt type template. The format of tt follows that of AS3_Object(). The parameters following tt should all be pointers to variables of the expected type. If a named entry in tt does not appear in in the Object, it is ignored. If a named member of the Object does not appear in tt , it is ignored.
Example:
int arg0 = 0; char* arg1 = NULL; double arg2 = 0.0; AS3_ObjectValue(obj, "foo:IntType, bar:StrType, baz:DoubleType", &arg0, &arg1, &arg2);
Assuming the Object obj contained the named elements and the types are correct, all the variables will be initialized from the Object.
This method does a lookup on the object passed for the named property.
The function returns the named property for that object. This will call a "getter" function if present. If the value is not found, NULL is returned.
Example:
AS3_Val length_property = AS3_String("length"); AS3_Val length = AS3_GetS(byteArray, length_property); AS3_Release(length_property);
This method is the same as AS3_Get() but uses a const char* instead of an ActionScript String for the property name. The return value is the same.
Example:
AS3_Val length = AS3_GetS(byteArray, "length");
This method does a lookup on the object passed for the named property.
The function sets the named property for that object to the value passed. This will call a "setter" function if present. No value is returned.
Example:
AS3_Val position_property = AS3_String("position"); AS3_Val zero = AS3_Int(0); AS3_SetS(byteArray, position_property, zero); AS3_Release(zero); AS3_Release(position_property);
This method is the same as AS3_Set() but uses a const char* instead of an ActionScript String for the property name. No value is returned.
Example:
AS3_Val zero = AS3_Int(0); AS3_SetS(byteArray, "position", zero); AS3_Release(zero);
Calls the ActionScript function func on the object thiz passing params .
Example:
AS3_Val baNS = AS3_String("flash.utils"); AS3_Val baClass = AS3_NSGetS(baNS, "ByteArray"); AS3_Val emptyParams = AS3_Array(""); AS3_Val ba = AS3_New(baClass, emptyParams); AS3_Val readUTFBytes = AS3_GetS(ba, "readUTFBytes"); AS3_Val lenParams = AS3_Array("IntType", strlen(buf)); AS3_Val str = AS3_Call(readUTFBytes, ba, lenParams);
Same as AS3_Call but func is a const char* and required to be a function on the object passed as thiz .
Example:
... AS3_Val str = AS3_Call("readUTFBytes", ba, lenParams);
Calls the ActionScript function func on the object thiz passing an ActionScript Array constructed using tt and other parameters.
In this method, the Array passed to func is constructed from tt and the parameters following.
Same as AS3_CallT but func is a const char* and required to be a function on the object passed as thiz .
Example:
... AS3_Val str = AS3_CallTS("readUTFBytes", ba, "IntType", 16);
Create a C function pointer that thunks to thiz.func(...).
int (*myfunc)(const char *s, double n) = AS3_Shim(someFunc, someThiz, "IntType, StrType, NumberType", false);
The function pointer is PERMANENT!
Create a Proxy object that delegates callProperty, etc. to the Function vars in the object in the flash_delegate namespace!
i.e., delgates to flash_delegate::callProperty, not public callProperty.
This is the typedef Alchemy uses for C/C++ function callbacks.
typedef AS3_Val (*AS3_ThunkProc)(void *data, AS3_Val params);
Create a synchronous function callback object, binding the function pointer with the data passed in.
Create an asynchronous function callback object, binding the function pointer with the data passed in.
Create an synchronous function callback object , binding it with the data passed in.
Create an asynchronous function callback object, binding it with the data passed in.
This method notifies the runtime that the library has initialized.
This call does not return, so no code should be placed after it. If this is not called from your C program, the runtime will never get the chance to execute any code outside of your C program (like updating the stage). For an example of using this -- see the AS3Lib project from the Alchemy samples.
This method returns the runtime stage object (typically ConSprite). You can then perform actions on it to manipulate the stage.
This method returns the ByteArray that represents all of the RAM for your C program. Since you are using that RAM, be very careful what you do with it!
This method will force the Alchemy state machine to give up it's time slice. Execution will return to the line following this call on the next Alchemy time-slicing timer tick.
This method will print the msg to the log and to the trace window if running in FlexBuilder or to STDOUT if running with swfbridge.
This method will print the value passed to the log and to the trace window if running in FlexBuilder or to STDOUT if running with swfbridge.
Reads len bytes from the ByteArray src at the current position into the buffer pointed to by dst .
Writes len bytes from the buffer src into the ByteArray dst at the current position.
Adjust the position in the ByteArray dst according to "lseek" style rules.