Writing scripting Xtras for Director/Authorware easy....
You can easy write Xtras for Director/Authorware
with XtraBuilder, you do not need Xtra Development Kit, because XtraBuilder
contains it.
We will write Memory Information Xtra, because this is the most simple, use
only one WINAPI function.
Requirements
The following software is the minimum required to author Xtras on Windows9x/NT:
Introduction of XtraBuilder
(from XtraBuilder document)
XtraBuilder is an application designed to make creating Xtras easier. There are four different types of Xtras – script, asset, tool and transition. XtraBuilder only creates script Xtras. Creating Xtras is a complicated task. Macromedia has available an XDK – Xtra Developers Kit – which provides the basic framework for building Xtras using Microsoft Visual C++ for Windows or Metroworks CodeWarrior for Macintosh. The XDK consists of a number of source and header files that must be included in a Xtra project. Unfortunately, the XDK is very complex and the samples provided by Macromedia are not exactly clear. Working out how the XDK works and what changes you have to make to create your own Xtra can take a considerable amount of time and effort. The aim of XtraBuilder is to create a set of files that ‘wrap’ around the XDK and provide you with a place to enter your own code. This enables you to make Xtras without understanding how the XDK works. Naturally, understanding what is going on is important, but XtraBuilder allows you to get started and investigate the XDK at a more leisurely pace.
Let' s start to write MemoryInformation Xtra
Installing and starting XtraBuilder
XtraBuilder is provided as a XtraBuilder.exe
file containing all the necessary XDK files, XtraBuilder and it’s associated
files, and a Visual C++ version 6 project. To start a new project, run the
XtraBuilder.exe file and unzip the files into a new folder, making sure that
the directory structure is kept intact. Inside your project folder will be
3 folders – Includes, Source and Winproj. Includes holds the standard XDK
header files; Source contains some modified XDK files and the XtraBuilder
files; Winproj contains the xtra.dsw file which is the Visual C++ Workplace
file. The first thing to do is to start Visual C++ and open up the xtra.dsw
file. This will load the project, which you will notice will contain a number
of files. There are only two files you need to concern yourself with to begin
with – code.c and functions.h. Code.c is the file that you will add your own
code into; functions.h will contain the function declarations for your functions.
This file is maintained by XtraBuilder.
After loading the project, you can start XtraBuilder – it is the xbuild.exe
file located in the Source folder.
The Load functions from DLL lets you specify a DLL file that you will load your functions from – you can do this instead of writing the functions directly into the xtra. We do not use it now.
With Update source code button you can update C source code, and Save button you can save your work.
Adding functions
Next you need to define the functions
that your Xtra will contain. Click on the Function list tab.

This screen contains a list where you can enter the names of the functions
you want your Xtra to contain. You can also specify whether each function
is active – if active, then the function will be included in the Xtra. To
enter a function, click in the Name field and enter the name of your function.
Then enter either ‘yes’ or ‘no’ in the Active field. As you add a function,
a new blank entry will be added at the end of the function list. Also, a new
tab will be added with the name of the function. This tab will contain specific
information relating to that function.
Macromedia recommends that you prefix the name of your function with a unique identifier. The reason for this is that there is no way for Authorware or Director to determine which function to use if two Xtras contain functions with the same name. For example, if two Xtras both contain a FileExists function, then there is no way to know which Xtra will be used.
Filling out function details

Each function will have its own
tab, where you can enter the details of the function; things such as the parameters
it takes, and the type of return it gives.
The Arguments list holds the list of arguments for this function; the
type of argument – ‘string’ or ‘integer’ – and the name of the argument. You
can add as many arguments as you need. The Return is the type of return
the functions returns – choose from void, integer, string, string pointer,
linear list or property list. If you choose string then you will also need
to enter the maximum number of characters to return. If the function displays
a dialog box then you should select the Shows dialog box check box.
This allows Authorware and Director to redraw its window while the dialog
box is being displayed. The Comment field is where you enter a comment
or instruction to the user about how to use the function. This will show up
at the bottom of the Authorware functions box and in Director’s message window.
The Called function field is where you enter the name of the function
(which you will write) that gets called when the function is called in the
Xtra.
Writing C code
#include "xtrautil.h"
long doGetTotalPhysicalMemory( XtraInfo * xtraInfo );
Before we writing
the code, must read some WINAPI functions, that we will use.
GlobalmemoryStatus, MEMORYSTATUS,
ZeroMemory, sizeof.
long doGetTotalPhysicalMemory(
XtraInfo * xtraInfo )
{
MEMORYSTATUS stat;
Before we can use a variable in
a C program, it must be declared. A variable declaration tells the compiler
the name and type of a variable and optionally initializes the variable to
a specific value. If your program attempts to use a variable that hasn't been
declared, the compiler generates an error message. A variable declaration
has the following form:
typename varname;
Typename specifies the variable type, the name can contain letters, digits,
and the underscore character (_). The first character of the name must be
a letter. C keywords can't be used as variable names. A keyword is a word
that is part of the C language. Important C language is case sensitive.
MEMORYSTATUS is a structure. A structure is a collection of one or more variables
grouped under a single name for easy manipulation. The variables in a structure,
unlike those in an array, can be of different variable types. A structure
can contain any of C's data types, including arrays and other structures.
Each variable within a structure is called a member of the structure. Individual
structure members can be used like other variables of the same type. Structure
members are accessed using the structure member operator (.), also called
the dot operator, between the structure name and the member name.
C statements are generally written one per line and always end with a semicolon.
GlobalMemoryStatus
(&stat);
return stat.dwTotalPhys;
}
Code looks this:
#include <windows.h>
// declarations
for your functions
#include "functions.h"
// declarations
for your global variable
MEMORYSTATUS stat;
long doGetTotalPhysicalMemory(
XtraInfo * xtraInfo )
{
ZeroMemory(&stat,sizeof(stat));
stat.dwLength = sizeof(stat);
GlobalMemoryStatus (&stat);
return stat.dwTotalPhys;
}
You can find compiled Xtra in XtraBuilder>Projects
directory. Copy myXtra.x32 into your Director>Xtras directory. Start Director,
open Message window then write:
put aGetTotalPhysicalMemory()
-- 133722112
Wow it works !
Exercises
Finish MemoryInformation Xtra functions. If you break down, you can find
full source code here:
(4 Kbyte)
Acknowledgments
Special thanks to Gary Smith, author of XtraBuilder.