How Do I...

Example: Connect a script to a push button

Connect scripts and parts to add function No tip for this topic No example for this topic Test my script

In this example, the user can click on a push button to display a message box. The message box is created by a Smalltalk script accessed through an event-to-script connection.
Event Code Hook sample

Define the user interface shown above, then add a script to the part class:

  1. Select Script Editor in the lower-right corner of the Composition Editor to open the Script Editor.
  2. Use the Script Editor to write and save the following script:
    displayMessage
      | messageBox |
      messageBox := (CwMessagePrompter new)
         title: 'Hey!';
         messageString: 'Please do not press that button again.'.
      messageBox prompt.
     
    
  3. Select Composition Editor icon in the lower-right corner of the Script Editor to open the Composition Editor.
  4. Click mouse button 2 on the Push Button part to open its pop-up menu. (For UNIX, use mouse button 3.)
  5. Select Connect > clicked.
  6. Click on the free-form surface; then select Event to Script.
  7. In the displayed window, select the displayMessage script and then OK.

The connection appears as a single-headed arrow pointing to an icon representing the script. When the user clicks on the push button, the script connection accesses the displayMessage method, running the script that displays the message box.


[ Top of Page | Previous Page | Next Page | Table of Contents ]