Inheritance in NewtonScript

Exercises

1. In the Inspector, create three counter objects (see "A Counter Object" on page 79), each of which independently maintains a current count. Here's an example of using them:

counter1:Next()
1
counter2:Next()
1
counter2:Next()
2
counter1:Next()
2
counter3:Next()
1
counter1:Next()
3
A QuickTime movie of the solution is available.

2. Add a Reset function to the counter objects from Exercise 1 which individually resets the count of each object back to 0. Here's an example of using it:

counter1:Next()
4
counter1:Reset()
0
counter1:Next()
1
counter2:Next()
3
counter3:Next()
2
counter2:Reset()
0
counter3:Reset()
0
A QuickTime movie of the solution is available.

3. Create an application with two text buttons, one called "Multiply by 2", and one called "Subtract by 3". The application should also contain a numeric value starting at 10. Pressing the "Multiply by 2" text button should modify the numeric value (multiplying it by 2) and print it to the Inspector. Pressing the "Subtract by 3" button should subtract 3 from the value and print it to the Inspector. Here's an example of their operation:

<press Multiply>
20
<press Multiply>
40
<press Subtract>
37
<press Subtract>
34
<press Subtract>
31
<press Subtract>
28
<press Subtract>
25
A QuickTime movie of the solution is available, as is the completed project for different platforms (Mac OS, Windows 3.1 or Windows 95/NT).

4. Create an application with two sets of text buttons:

Multiply1 and Subtract1 which modify one numeric value
Multiply2 and Subtract2 which modify a different numeric value

each of which operates as in Exercise 3. For example:

<press Multiply1>
20
<press Multiply1>
40
<press Multiply2>
20
<press Subtract1>
37
<press Subtract1>
34
<press Subtract2>
17
<press Subtract2>
14
A QuickTime movie of the solution is available, as is the completed project for different platforms (Mac OS, Windows 3.1 or Windows 95/NT).

5. Create an application with two text buttons. Create a name slot in the application (called app) and name slots in each of the two buttons with the values "button1" and "button2". Create a PrintName slot in the protoApp which prints out the value of name. Make the first button send the PrintName message to its parent (the protoApp). Make the second button send the PrintName message to itself. How do they differ?

A QuickTime movie of the solution is available, as is the completed project for different platforms (Mac OS, Windows 3.1 or Windows 95/NT).


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996