Adobe Extending Flash Professional CS5 User Manual
Page 551
529
EXTENDING FLASH PROFESSIONAL
C-Level Extensibility
Last updated 5/2/2011
•
Mac
OS X:
Macintosh HD/Users/username/Library/Application Support/Adobe/Flash CS5 or
CS5.5/language/Configuration/External Libraries
4 Create a JSFL file that calls the functions.
5 Run the JSFL file from the Commands menu in the Flash authoring environment.
C-level extensibility and the JavaScript interpreter
The C code in the DLL or shared library interacts with the Flash JavaScript API at three different times:
•
At startup, to register the library’s functions
•
When the C function is called, to unpack the arguments that are being passed from JavaScript to C
•
Before the C function returns, to package the return value
To accomplish these tasks, the interpreter defines several data types and exposes an API. Definitions for the data types
and functions that are listed in this section appear in the mm_jsapi.h file. For your library to work properly, you must
include the mm_jsapi.h file at the top of each file in your library, with the following line:
#include "mm_jsapi.h"
Including the mm_jsapi.h file includes the mm_jsapi_environment.h file, which defines the MM_Environment
structure.
To get a copy of the mm_jsapi.h file, extract it from the sample ZIP or SIT file (see “
page 532), or copy the following code into a file that you name mm_jsapi.h:
#ifndef _MM_JSAPI_H_
#define _MM_JSAPI_H_
/*****************************************************************************
* Public data types
****************************************************************************/
typedef struct JSContext JSContext;
typedef struct JSObject JSObject;
typedef long jsval;
#ifndef JSBool
typedef long JSBool;
#endif
typedef JSBool (*JSNative)(JSContext *cx, JSObject *obj, unsigned int argc,
jsval *argv, jsval *rval);
/* Possible values for JSBool */
#define JS_TRUE 1
#define JS_FALSE 0
/*****************************************************************************
* Public functions
****************************************************************************/