previous chapter chapter"> contents
page top
page next chapter chapter">

SimpleActionButton

April 1, 1994

Defined in Button.Def
Inherits from Button

Class Description

Some buttons perform actions that are simply calls to a single method of another object. You could script the button, or you could subclass Button just to override Action. Does subclassing seem like overkill? Use class SimpleActionButton instead! Simple action buttons have a target object and a target operation. When the user taps, the system calls the target operation.

Remember that if the documentation and the software (especially the definition files) disagree, always trust the software.

Using a SimpleActionButton Object

Simple action buttons work just like regular buttons: the user taps, and the button initiates some action.

Programming Information

Instantiate: often
Subclass: rarely
Call its methods: rarely

You will rarely need to subclass SimpleActionButton or call its methods directly. You will usually just include simple action buttons in your packages by including instances in an object definition file.

Here's an example of a simple action button that adds a new page to the notebook:

Instance SimpleActionButton 'new' 1244;
           next: (SpecialButton 'index' 1568);
       previous: (NoteCard 895);
      superview: (NotebookScene 'Notebook' 516);
        subview: nilObject;
 relativeOrigin: <211.0,-52.5>;
    contentSize: <50.0,42.0>;
      viewFlags: 0x10101000;
     labelStyle: iBook10Bold;
          color: 0xFF000000;
       altColor: 0xFF000000;
         shadow: nilObject;
          sound: iTouchSound;
          image: (Image 'new' 1570);
         border: (BorderImage 3189);
         target: (ContainerWindow 'Select a new page' 7677);
      operation: operation_ShowOrHide;
End Instance;

The button's target is a container window that displays the various choices for a new notebook page. The target operation is ShowOrHide. When the user taps this simple action button, the system calls the ShowOrHide method, which displays the window if it wasn't previously visible.

Methods you might call

The SimpleActionButton class defines the following methods:

Method Description
Action Call the target operation on the target object
Touch Called when the user touches your button
Target Get the target field
SetTarget Set the target field

Description of fields

The SimpleActionButton class defines the following fields:

Field Type Description
target Object The button's target
operation Unsigned Settings for the button, including the operation targeted

Fill in the operation field with the operation you'd like the button to call. If the button is calling a system method, you can specify the operation like this:

operation_MethodName

If the operation you're calling is a package operation, though, this won't work. In that case, specify the operation using the operation number with its high bit set. Here's an example of a simple action button that calls a package operation, taken from the calculator sample:

Instance SimpleActionButton 'Erase' 64;
           next: nilObject;
       previous: (Box 30);
      superview: (Box 'Paper Tape' 35);
        subview: nilObject;
 relativeOrigin: <0.0,80.5>;
    contentSize: <66.0,19.0>;
      viewFlags: 0x10101000;
     labelStyle: iBook12Bold;
          color: 0xFF000000;
       altColor: 0xFF000000;
         shadow: nilObject;
          sound: iTouchSound;
          image: nilObject;
         border: iStandardButtonBorderUp;
         target: (PaperTape 19); // PaperTape $B840004A
      operation: 32968; // EraseAll (Package Op number 200)
End Instance;

Just add 32768 (215) to your package operation number. Since operation numbers aren't easily readable by human beings, it's a good idea to comment the operation number field with the name of the operation.

Usually you want your simple action button to act after the user's finger lifts, to give her a chance to change her mind about tapping the button. You'll want the action of a few buttons to take place immediately, though. For those buttons, the system defines a handy mask:

#define kOperationOptionMask0x40000000

Set this bit of the operation field to make your button act on the down stroke.

Method Descriptions

You probably won't call any of the methods of class SimpleActionButton yourself, but since it defines so few, all are documented here.

Touch

overrides Touch(touchInput: TouchInput)
call: sometimes
Override: rarely

If the kOperationOptionMask is set, Touch plays the button's sound then calls Action. If the flag isn't set, Touch calls its inherited method.

Action

overrides Action()
call: sometimes
Override: rarely

Action checks the operation field and extracts the operation to be called. It calls OperationByNumber on the target, thus dispatching a call to the operation.

TargetSetTarget

attribute Target: Object, safe
// operation Target(): Object
// operation SetTarget(newTarget: Object)

Call Target and SetTarget to get and set the contents of the target field.