Creating a Behavior-based DropTool

This is the most common form of DropTool: a control that has all of its scripts inside a separate behavior button, and has very little (or no) scripts inside itself. It usually requires support resources, such as images.

What is the Advantage to Using a Behavior?

If you have multiple instances of your control being used, if they were prescripted then the code is copied over and over again for every instance. If you use a behavior, there is only one instance of the script that is being used by multiple instances of the control. This not only saves space but also makes it easier to update or change the way your control works - you only need to update one script instead of every script of every instance of your control.

The DropTool in this example is a behavior-based variation of the prescripted "Next" button example. If you haven't looked at that example yet, you should review it before looking at this example.

It looks like this: Has a behavior button... ...which has this simple script:
on mouseUp
go next card
end mouseUp

To make the DropTool, take the same steps as for the prescripted version, plus the two extra steps (#6 and #7) shown in bold below:

  1. Open the
    DropTool Template.livecode
  2. Copy and paste the button from your stack onto the DropTool Template stack. (If you hadn't already created it, you can create it from scratch on the first card of the DropTool Template stack.)
  3. Since custom controls must be in a group, make sure your button is selected and then group it (adjust the margins of the group if you like).
  4. Give your control group the name
    (this is its DropTool "type").
  5. Change the name of the stack from "DropTool Template" to
    (same as your control). (You can change the title as well if you like.)
  6. Add a button to hold your behavior and set its script to the script above.
  7. Change the name of the behavior button to "NextButton Behavior"
As with the prescripted version, you can change the values in the
custom property set for the stack to correspond to your own "about" information, or delete the custom property set in its entirety if you don't want to provide any "about" info.

You can also make the stack "clean" by deleting the extra About and Inspector substacks and the instructions field on the main card if you like.

File > Save as...
and save your stack in the DropTools folder.

Close the stack in LiveCode, and then open the DropTools Palette (or close and reopen it) and your control should work as you'd expect, but it uses a behavior instead of being prescripted.

© 2015 Sons of Thunder Software, Inc.