User Guide

Data types 375
long a, b, sum;
// Make sure the right number of arguments were passed in
if (argc != 2)
return JS_FALSE;
// Convert the two arguments from jsvals to longs
if (JS_ValueToInteger(cx, argv[0], &a) == JS_FALSE ||
JS_ValueToInteger(cx, argv[1], &b) == JS_FALSE)
return JS_FALSE;
/* Perform the actual work */
sum = a + b;
/* Package the return value as a jsval */
*rval = JS_IntegerToValue(sum);
/* Indicate success */
return JS_TRUE;
}
After writing this code, build the DLL file or shared library, and store it in the appropriate
External Libraries directory (see “How integrating C functions works” on page 369). Then create
a JSFL with the following code, and store it in the Commands directory (see “Overview of the
Macromedia Flash JavaScript API” on page 17).
// JSFL file to run C function defined above
var a = 5;
var b = 10;
var sum = Sample.computeSum(a, b);
fl.trace("The sum of " + a + " and " + b + " is " + sum );
To run the function defined in the DLL, select Commands > Sample in the Flash authoring
environment.
Data types
The JavaScript interpreter defines the following data types:
JSContext
JSObject
jsval
JSBool
typedef struct JSContext JSContext
A pointer to this opaque data type passes to the C-level function. Some functions in the API
accept this pointer as one of their arguments.
typedef struct JSObject JSObject
A pointer to this opaque data type passes to the C-level function. This data type represents an
object, which might be an array object or some other object type.