If you write a lot of Actions Editor code, you've likely run into the situation where you write yourself a nice routine to accomplish a specific task, and then you find yourself writing it over and over again as you utilize that logic in various places in your ToolBook file.
Wouldn't it be nice if you could write it once - storing it in some central place within your book, and then "call it" from any object within that same book? Well, that's exactly what a Shared Action is for.
Let's assume you have written the following logic to take a numeric value entered by your user, and format it into a proper looking dollar amount.
For example if the value 26 is entered, this script will convert that to $26.00.
Writing standard Actions Editor logic in the Actions Editor would look something like this:
If you had dozens of places within your book where you wanted to process numbers into dollar amounts, you could utilize this same logic, and end up scattering copies of this logic throughout your book. Of course if you later decided there was a mistake in the logic, you'd have to correct the mistake in each occurrence of this logic.
Or you could convert this into a single Shared Action, and simply call it from those various places.
Create a new Shared Action by:
There is one piece of information we need to pass into this Shared Action, and that is the amount the user typed into the field. As such, open the Variables editor within the Shared Action editor and create a new Parameter named "value".
Next, recreate the existing logic but this time within this Shared Actions editor.
Note that the Shared Actions editor shows you which parameters can be passed into this Action by the Execute Shared Actions action. It also shows you that the variable named returnValue will be used as the value returned back to the Execute Shared Actions action (which you'll see later).
Now that the Shared Action is written, close the editor (saving changes) and rename it from NewActionBlock to something more meaningful such as NumberToDollar.
Now that the Shared Action is fully created, we need to "call it" from some other Actions Editor code. To call one of your Shared Actions, use the Execute Shared Actions action found in the General category.
This new logic will:
To fully configure the Execute Shared Actions action once added to your programming window, you will need to open the Properties for Execute Shared Actions action. You can do this by selecting the line, and clicking the Properties button from the tool bar.
From within the Properties you can see choose which Shared Action to call, and specify the values to be used for any parameters, as well as which variable to put the return value into.
If you would like to share one of your Shared Actions with someone else, ToolBook does offer the ability to Export a single Shared Action into a external file, stored with a .TBA extension. This .TBA file can then be sent to another ToolBook user and that TBA file can be imported into another ToolBook file.
To access this import/export feature, access the Shared Actions listing from the Object menu.
Created with the Personal Edition of HelpNDoc: Free EPub producer