The BlackBox Builder is a special database that you can use to build your own BlackBoxes. You can then use these BlackBoxes as building blocks in your own FileMaker solutions, or you can even make them available to other FileMaker developers.
Anatomy of a BlackBox
BlackBox Functions
The BlackBox that you create will contain one or more BlackBox Functions, and once your BlackBox is installed, those functions will appear in FileMaker's own function list, grouped together under the "Reactor" heading in the External functions section. It's a little bit like creating custom functions within FileMaker, but a lot more powerful.
Typically, you will be creating BlackBox Functions that will implement superb new user interface controls for use in your FileMaker layouts. Sometimes your BlackBox may provide more than one type of control, in which case the BlackBox itself will have multiple functions. The CalPack BlackBox, for example, contains three functions which deliver three different types of calendar controls.
BlackBox functions come in two flavors: WebTech Functions are the superstars, delivering sophisticated controls using a range of web technologies like HTML, CSS, and JavaScript. You can also create FileMaker Calculation functions, which allow you to perform straightforward FileMaker calculations — these are very similar to FileMaker's own custom functions, but have the advantage that they get parcelled up and carried around effortlessly inside your BlackBox. Sometimes the functions inside your BlackBox may even call each other as part of a team endeavor to deliver your finished control.
Project Files
The other important component that will be involved in creating your BlackBox is a set of Project Files. These are HTML, CSS, and JavaScript files, image files, etc., all of which pull together to build up the control delivered by your WebTech Function(s).
Project files live on your hard disk drive while you are developing your BlackBox. They work very much like similar files would work to create a web-based application, but when you build your BlackBox they will get bundled up inside, ready to deliver their promise later inside a Web Viewer on your FileMaker layouts.
Creating a BlackBox
Getting Started
The BlackBox Builder is a FileMaker database that will help you organise and build your BlackBoxes. We'll build a simple BlackBox called DemoBB as an example here. If you get confused, or something goes wrong, just take a fresh copy of the BlackBox Builder and start again.
DemoBB is a very simple BlackBox that does absolutely nothing useful. It delivers a simple BlackBox control that you can place on a FileMaker layout purely to demonstrate some features of BlackBox creation. To create a new BlackBox, click the Create/Import… button on the Main Screen, enter the name of your new BlackBox in the dialog, and click the Create button.
 |
|
Click for full-size image |
The Main Screen
Below is a snapshot of the BlackBox Builder main screen, showing DemoBB. On the left hand side is a list of all your BlackBoxes, and buttons for creating, importing and deleting them. Clicking on a BlackBox's name selects it and displays its details in the main panel. Let's take a tour of this panel, starting at the top:
- BlackBox Name — Every good BlackBox has one. This will be used as the filename for the finished portable BlackBox file. Alongside it is a field for the version number, so you can distinguish between new or legacy versions.
- Description — Write up an overview of what the plugin does. Particularly useful if you plan to share the BlackBox, this is also useful to remind yourself what your plans for the plugin are.
- The Help Page field can contain a URL to a page that describes how to use the BlackBox. This URL can be accessed by the BlackBoxHelp("DemoBB") function built into Reactor, and is a good way to provide detailed instructions on its use to a wider audience.
- On the right, the Compiled BlackBox container will hold the BlackBox once it has been built. You can click the 'Load' or 'Remove' buttons to place or delete the BlackBox file in the correct location on your machine so that it will be available in the External functions section (building a BlackBox will automatically load it).
- The Build Count field will automatically increment every time you build a BlackBox – likewise, the Modified and Created fields will help you keep track of changes to your BlackBox. You can add your name to the Author field, too, so others can tell who created this awesome piece of coding wizardry.
 |
|
BBB Main Screen.png |
The Functions Tab
This tab displays details of the functions that this BlackBox will provide. On the left is a list of functions which can be clicked to be selected, along with Create and Delete buttons. Click the Create… button, and enter 20001 as the Function ID to create a new function for the DemoBB BlackBox. Let's name it DemoControl. At the top of this panel are the following fields:
- Name — This is the name of the function, as it will appear in FileMaker's external function list (under the Reactor heading)
- Function ID — This is a unique numeric ID that identifies each function and differentiates it from all other functions loaded into FileMaker. Whenever you make a new BlackBox function, you'll be asked to supply one of these IDs. Eventually we will set up a registry of function IDs to avoid collisions; in the meantime you should use values between 20,000 and 32,000, and take care not to install BlackBoxes with conflicting IDs.
- Function Type — DemoControl is a WebTech Function. It will use web technologies to deliver its stunning result.
- Start Page — Every WebTech Function will load up a main 'page' in the web viewer. This page will always be one of your project files.
 |
|
BBB Functions Tab.png |
Below these fields is a portal listing the parameters for the selected function. All FileMaker functions need to have at least one parameter, even if we don't intend to pass them anything useful. Click on the Add Parameter… button to create the DemoControl function's only parameter, and name it YourNameGoesHere. Let's work through the attributes of that parameter:
- Parameter Name — This is the 'official' name of the parameter, and it's how you'll refer to it inside your HTML & JavaScript (see later, under "So how did that work?").
- Display String — This is the what the parameter will look like when it appears in the function template that you get when you double-click on the function name in FileMaker's function list. We'll take care of the semicolons between parameters, and the curly braces around optional parameters, but you might want to add other characters to the Display String; for example in our own BlackBoxes we put double-quotes at either end to help indicate when we want a parameter that is the actual name of a FileMaker field, rather than a field reference.
- Data Type — Defaults to text, which is usually fine, but if you are passing date values in particular you will want to set this appropriately (more information about Parameter Data Types).
- Optional — You can mark a parameter as optional, and FileMaker will then not require you to supply a value if you don't want to. In FileMaker's function list, curly braces are shown surrounding optional parameters.
- Hidden — If you want to, you can even mark a parameter as hidden. In this case the parameter won't show up at all in FileMaker's function list, but savvy developers can still supply a value if they want (and know!) to.
Note: Optional parameters, and also hidden parameters, can only appear at the end of the parameter list, for obvious positional reasons. You can have more than one of each, and one or more parameters can be both optional and hidden if required, but each type must not be interspersed with their non-optional or non-hidden brothers and sisters. Don't worry: the parameter sorter will wave red flags at you if you get them mixed up, and the build process will stop and yell at you.
- Refresh — The Refresh flag indicates that this parameter's value will be included in the URL that will be the result of this function. Generally speaking you will want this option to be checked: without going into the technicalities, a change in the value of this parameter will then cause your Web Viewer to reload. It will also ensure that multiple instances of this BlackBox control used on the same layout will behave as individuals as long as they have different values for these parameters.
The order of the parameters can be set by clicking the Sort Order… button, which displays the function and its parameters as they would appear in the calculation screen. Just drag the parameters around to change their order. (How does that sorter work? It's a Reactor BlackBox Control, of course!).
The Project Files tab
Every WebTech function requires at least one project file, and even our trivial DemoBB is no exception. While you're developing your BlackBox, project files reside on your own computer, and you edit them there during the development process. When you build the BlackBox, copies of these files are packaged up along with other information to form a single distributable BlackBox file.
Now that you have your project file, you can nominate it as the Start Page for the DemoControl function. Do that now, on the Functions tab.
In the bottom-right corner is a Build BlackBox… button. Each time you hit this button, the BlackBox Builder will gather up all the information you have entered about your BlackBox (function names, parameters, etc.), scoop up current copies of all the project files, and package them all up into a single compiled BlackBox file. It will then save this file into your own FileMaker Extensions directory, and even load it into FileMaker so that you can start testing it straight away. Typically you'll have a test database open off to one side that uses the BlackBox control you're working on, and after hitting the build button you can swap straight to that and start testing it (although, naturally, your code will work perfectly the first time!)
Going back to the Details tab, you will see a file in the
Compiled BlackBox container which can be used in your solution's deployment. If you are
Deploying Reactor with a Database, for example, you can deploy the BlackBox automatically by creating a new record in your Reactor Resources table and dragging the BlackBox into the new record's container.
Comments