home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Toolbook (Evaluation Edition) / Multimedia_Toolbook_Asymetrix_1992.iso / oworkbk.tbk / oworkbk.tbk (.txt)
Asymetrix ToolBook File  |  1992-10-25  |  266KB  |  3,366 lines

  1. Advanced topics
  2. Advanced topics
  3. startSection
  4. sectionNumber
  5. OpenScript applications
  6. OpenScript applications
  7. startSection
  8. sectionNumber
  9. -- When a chapter 
  10. clicked update the section list.
  11. 4s_DidDoubleClick
  12. updateSectionList
  13. oselectedTextLines
  14. strip(
  15. -- If 
  16. user presses a key that 
  17. reflect 
  18. -- Algorithm:
  19. -- Get 
  20. currently 
  21. . Forward 
  22. keystroke 
  23. ToolBook 
  24. default processing. Check 
  25. -- changed. If so, 
  26.  message 
  27. sections.
  28. causes 
  29. respond 
  30. -- Update 
  31. 4s_currentSection
  32.     -- Set 
  33. "Chapter 
  34. 3Name" 
  35. "Sections" 
  36. commandLine 
  37. sectionList 
  38. " && "
  39.     -- Clear 
  40. buttonDoubleClick
  41. buttonUp
  42. keyDown
  43. updateSectionList
  44. buttonUp
  45. updateSectionList
  46. s_DidDoubleClick
  47. buttonDoubleClick
  48. strip
  49. s_DidDoubleClick
  50. keyDown
  51. updateSectionList
  52. updateSectionList
  53. Chapter Name
  54. strip
  55. set sectionList to
  56. Sections
  57. of this page
  58. Sections
  59. Sections
  60. sectionList
  61. commandLine
  62. s_currentSection
  63. Title
  64. E v a l u a t i o n   E d i t i o n
  65. E v a l u a t i o n   E d i t i o n
  66. Welcome
  67. uy ToolBook
  68. default
  69. default
  70. Title
  71. myAuthor
  72. myAuthor
  73. author
  74. OpenScript Workbook
  75. OpenScript Workbook
  76. -- Animate the message spark through 
  77. hierarchy 
  78. Hsending 
  79. -- moveLSpark 
  80. /. The 
  81. Ualong which 
  82. travel.
  83. showMe
  84. 4s_flag
  85. \"et1"
  86. f"et2"
  87. p"et3"
  88. "et4"
  89. "et5"
  90. done 
  91. following 
  92. handlers are used 
  93. asure 
  94. user 
  95. prompted 
  96. example 
  97. "Show Example" 
  98. Bhas 
  99. xbeen clicked but
  100. Rtries 
  101. leave 
  102. StrTryMsg() 
  103. fStrShowDemo() 
  104. StrNoDemo()
  105. SysLockScreen 
  106. leaving 
  107. && "can 
  108. %animated examples 
  109. && "messages 
  110. sent 
  111. . You normally"\
  112. && "trigger each demonstration 
  113. Hclicking 
  114. && """
  115. Bon that 
  116. Would 
  117. like 
  118. see the"\
  119. instead 
  120. moving on 
  121. "&No 
  122. rPage
  123. showMe
  124. enterPage
  125. leavePage
  126. rTryMsg
  127. StrShowDemo
  128. StrTryMsg
  129. StrNoDemo
  130. showMe
  131. moveLSpark
  132. moveLSpark
  133. moveLSpark
  134. moveLSpark
  135. moveLSpark
  136. s_flag
  137. enterPage
  138. s_flag
  139. StrTryMsg
  140. StrShowDemo
  141. StrNoDemo
  142. StrShowDemo
  143. Show Example
  144. buttonDown
  145. buttonUp
  146. s_flag
  147. leavePage
  148. s_flag
  149. StrTryMsg
  150. The page you are leaving and the following pages
  151. can show you animated examples of how
  152. messages are sent along the hierarchy. You normally
  153. trigger each demonstration by clicking the yellow
  154. "Show Example" button on that page.  Would you like to see the
  155. demo for this page instead of moving on to the next page?
  156. StrShowDemo
  157. &Show Example
  158. StrNoDemo
  159. &No Demo
  160. The Pattern Property
  161. Background Objects
  162. Mouse movement and button messag
  163. To get and To set Handlers
  164. Book Editor
  165. Local versus System Variables
  166. Branching with If/then/else
  167. Branching control structures
  168. User-defined messages 1
  169. Expressions
  170. sectionNumber
  171. startSection
  172. Expressions
  173. An expression is a way of combining or specifying values in OpenScript. For example, the following are expressions:
  174. 125 + 77
  175. (text of field "Cost" - 5)
  176. An expression has a result. The result of the first expression is 202. The result of the second expression depends on the contents of a field named "Cost."""eld named "Cost."
  177. Using the debugger to interrupt 
  178. sectionNumber
  179.     A looping control structure whose ending condition is never met is called an endless loop. If you run a handler that contains an endless loop your computer may appear broken. Fortunately, you can interrupt a running handler so you can edit the script and fix it.
  180. 1.    Switch to Reader level.
  181. 2.    Click the "Endless Loop" button.
  182.     This button's script contains an endless loop.
  183. 3.    Hold down both Shift keys until the Debug window appears.
  184. 4.    To return to ToolBook, choose Exit Debugger from the Options menu.
  185.     To find out more about how to use the Debug window, see ToolBook Online Help.g Scripts," in Using OpenScript.
  186. Using Shift+Shift to interrupt an endless loopp
  187. Endless Loop
  188. -- This handler 
  189. endless loop. The 
  190. _tests
  191. -- i 
  192. will 
  193. 'than 
  194. equal 
  195. zero. However,
  196. -- i starts 
  197. increases so the ending condition 
  198. -- never met. Press Shift+
  199. -- running 
  200. interrupt 
  201. TDebug 
  202. ci > 0
  203. buttonUp
  204. buttonUp
  205. Endless Loop
  206. Types of expressions
  207. Types of expressions
  208. There are three types of expressions in OpenScript:
  209. numeric        Results in a number (e.g. 10 / 3 = 3.33333333)
  210. string            Results in a string 
  211.                 (e.g. "Cat" & "Mouse" = "CatMouse")
  212. logical        Results in true or false (e.g. 6 > 11 = false)
  213. The following exercises allow you to explore writing expressions and predicting their results.lts..
  214. sectionNumber
  215. Building expressions
  216. sectionNumber
  217.     An expression consists of one or more values separated by operators like +, -,     &&, 
  218.     and so on. For example, "100", "100+5", 
  219.     and "3>5 or 5>3" are all expressions.
  220. 1.    Switch to Reader level.
  221. 2.    Use the lists of values and operators to the right to build an expression. Click the values or operators you want in your expression. They will be added in the order you click them. You can also type directly in the "Expression" field.
  222. 3.    Predict the result of your expression, then click the "Show Result" button to see your expression's result in the "Result" field."Result" field......... in the "Result" field... the "Result" field....................
  223. Building expressions_
  224. -- If the current expression has already been calculated, 
  225. ;"Expression" 
  226. "Result" fields. In 
  227. M, place 
  228. pselected value 
  229. lineNum 
  230. <= 0; 
  231. W& " " 
  232. buttonUp
  233. buttonUp
  234. Expression
  235. Result
  236. textFromPoint
  237. Expression
  238. lineNum
  239. calculated
  240. 1.0e5
  241. false
  242. "Avacado"
  243. "Beet"
  244. "Carrot"
  245. "Eggplant"
  246. "Zucchini"
  247. -- Add the selected operator 
  248. expression.
  249. 4calculated
  250. "Expression"
  251. "Result"
  252. lineNum 
  253. <= 0; 
  254. " " & 
  255. W& " " 
  256. buttonUp
  257. buttonUp
  258. Expression
  259. Result
  260. textFromPoint
  261. Expression
  262. lineNum
  263. calculated
  264. is not
  265. contains
  266. is not in
  267. Value:
  268. Operator:
  269. Result
  270. Expression
  271. Expression:
  272. Test Result
  273. Result:
  274. Show Result
  275. -- Use the 
  276. function 
  277. expression 
  278. "Expression"
  279. . If there 
  280. error, display a 
  281.  message, otherwise, place 
  282. |result 
  283. "Result" 
  284. 4calculated
  285.     -- The following 
  286. Uputs 
  287. _succedes 
  288. 's syntax 
  289. handler can 
  290. . Trying 
  291. invalid 
  292. results 
  293. "Execution Suspended"
  294. "Test 
  295. " && 
  296. "This isn't a correct 
  297. . Remember," && \
  298. consists 
  299. values separated" && \
  300. Hoperators."
  301. buttonUp
  302. buttonUp
  303. Expression
  304. Test Result
  305. set a to
  306. Result
  307. This isn't a correct expression. Remember,
  308. an expression consists of values separated
  309. by operators.
  310. expression
  311. calculated
  312. Show Result
  313. Specifying parts of strings
  314. sectionNumber
  315.     You can refer to parts of strings in OpenScript.
  316.     For example, if you want characters two through
  317.     five of the string in the field to the
  318.     right you would type:
  319.     characters 2 to 5 of text of field "String"
  320.     If you want just character 10 you
  321.     would type:
  322.     character 10 of text of field "String"
  323.     To specify words use "word" rather 
  324.     than "character."
  325. 1.    Switch to Reader level then  
  326.     specify words 3 through 5 of the 
  327.     string by typing an expression in the
  328.      "String Specifier" field. Click the 
  329.     "Show Result" button to see the expression's result. Make up some other expressions and try them..
  330. Specifying parts of strings
  331. String
  332. The quick brown fox jumped over the lazy dogs.
  333. String:
  334. Show Result
  335. -- Use the 
  336. function 
  337. specifier
  338. ""String Specifier" 
  339. . If there 
  340. error display a
  341. message. Otherwise, place 
  342. result 
  343. "Result" 
  344. sSpecifier 
  345.     -- The following 
  346. Uputs 
  347. _succedes 
  348. 's syntax 
  349. handler can 
  350. . Trying 
  351. invalid 
  352.  results 
  353. "Execution Suspended"
  354. "Test 
  355. " && 
  356. "This isn't a 
  357. buttonUp
  358. buttonUp
  359. String Specifier
  360. Test Result
  361. set a to
  362. Result
  363. This isn't a valid string specifier. Try again.
  364. sSpecifier
  365. Show Result
  366. String Specifier
  367. characters 5 to 15 of text of field "String"
  368. String Specifier:
  369. Result
  370. quick brownnown fox jumped over the lazy dogs.
  371. Test Result
  372. "String"
  373. String
  374. Result:
  375. -- Table 
  376. Contents - 
  377. -- The 
  378. may be entered 
  379. 8. That 
  380. 's section 
  381. saved 
  382. -- s_currentSection 
  383. handler. 
  384. used 
  385. displayed.
  386. -- There 
  387. also a 
  388. -- marks a completed 
  389. chapter 
  390. Hplacing 
  391. -- asterisk beside its 
  392. -- When entering 
  393. (entry 
  394. -- corresponding 
  395. recorded 
  396.     -- Switch 
  397. Reader level
  398.     -- Hide 
  399. help 
  400.     -- Highlight 
  401. selectedTextLines 
  402. J"Chapters" 
  403. J"Sections" 
  404. -- Place 
  405. front 
  406. identified 
  407. x. If 
  408. sections 
  409. , place 
  410. markSection x
  411. chapterNum 
  412. sectionNum 
  413.         -- Get 
  414. list 
  415.         -- 
  416. propertyName 
  417. commandLine 
  418. " && 
  419. 5&& "
  420.         -- 
  421. fore 
  422. " && 
  423.         -- If 
  424. chapterDone 
  425. chapters 
  426. x"*" 
  427. enterPage
  428. markSection
  429. enterPage
  430. reader
  431. Chapters
  432. buttonUp
  433. Chapters
  434. Sections
  435. Sections
  436. currentSection
  437. s_currentSection
  438. markSection
  439. Sections
  440. of page "Table of Contents"
  441. of page "Table of Contents" to it
  442. Chapters
  443. Table of Contents
  444. chapters
  445. chapterDone
  446. commandLine
  447. propertyName
  448. sectionNum
  449. chapterNum
  450. Chapter Head
  451. Using the workbook
  452. Basic concepts
  453. Basic concepts
  454. startSection
  455. sectionNumber
  456. Elements of OpenScript
  457. Elements of OpenScript
  458. startSection
  459. sectionNumber
  460. OpenScript commands
  461. OpenScript commands
  462. startSection
  463. sectionNumber
  464. Lists
  465. Lists
  466. A list contains items which are separated by commas. For example, the following list contains four items:
  467. Oranges, Apples, Star Fruit, Kiwi
  468. Notice that even though "Star Fruit" is two words it is only one item since it is between commas. The following exercise allows you to experiment with lists and items....you to experiment with lists and items.....
  469. startSection
  470. sectionNumber
  471. Lists
  472. Changing an Object's Color Prope
  473. The sysCursor Property
  474. OpenScript Workbook
  475. Listing Objects using Push and P
  476.  on a Page
  477. Table of Contents
  478. Close the Workbook
  479. bjects from 
  480. Handling Standard Menu Choices
  481. Handlers in Backgrounds
  482. Table of Contents
  483. The OpenScript Workbook
  484.  1992 Asymetrix Corporation 
  485. All Rights reserved.
  486. Asymetrix OpenScript Workbook Team:
  487. Bob Gallup
  488. Carol Buchmiller
  489. Claude Ostyn
  490. Greg Pearson
  491. Brad Gaub
  492. Tom Arnold
  493. instructional design:
  494. Tec Ed, Ann Arbor, Michigan
  495. ichigan
  496. ructional design:
  497. Tec Ed, Ann Arbor, Michigan
  498. -- Go 
  499. the Table 
  500. Contents 
  501. buttonUp
  502. buttonUp
  503. Table of Contents
  504. Table of Contents
  505. Showing all objects on a page
  506.     If you want to show all objects on a page even if they are currently hidden, you can use the page's objects property.
  507. 1.    To show all objects on a page, type the following command in the Command window:
  508.     show objects of this page
  509.     This technique can be useful if you know there are hidden objects on the page but you don't know their names or IDs.
  510.     How would you hide the objects on this page? How would you show all objects on the background?
  511. Showing all objects on a page
  512. Button
  513. sectionNumber
  514. OpenScript Workbook
  515. January, 1991
  516. (c) Asymetrix Corporation
  517. gives you permission 
  518. e, revise 
  519. reuse the individual 
  520. scripts 
  521. your own applications.
  522. --You may 
  523. x, however, 
  524. Sentire 
  525. a substantial part 
  526. redistribution 
  527. jproduct.
  528. retains 
  529. copyright on 
  530. original elements 
  531.  . Include 
  532. notice "Portions 
  533.  are 
  534. they contain 
  535. copied 
  536. -- Special handling 
  537. Author 
  538. test drive version
  539. -- It does 
  540. xstop 
  541. clock, but prevents annoying messages
  542. -- due 
  543. frequent 
  544. cdoing 
  545. exercises 
  546. myAuthor 
  547. "Title" 
  548. "Welcome"
  549. -- When entering 
  550. 8, switch 
  551. Reader level, 
  552. -- environment, 
  553. cbar 
  554. status box.
  555. 4s_launchedFrom, s_changesDB, s_currentSection
  556. restoreEnvironment
  557. done 
  558. "The hierarchy 2" 
  559. leaving 
  560. -- Restore 
  561. _saving 
  562. contents
  563. . Also, 
  564. asure that
  565. -- ToolBook confirms 
  566. user exits 
  567. 8without
  568. -- System 
  569.     - Application 
  570. workbook
  571. setting 
  572. nproperty
  573. --            
  574. 8was opened
  575. FromAppSampler
  576. oldLaunchedFrom 
  577. oldFromAppSampler 
  578. sFromAppSampler
  579. oldChangesDB 
  580. beginning 
  581. a section,
  582. . If 
  583. marks 
  584. L list.
  585. -- This handler also unlocks 
  586. screen, forcing 
  587. image, 
  588. mouse cursor 
  589. hourglass 
  590. default shape.
  591. scomplements 
  592. , which 
  593. effective 
  594. notify 
  595. flipping 
  596. complete.
  597. 4s_sectionStarted
  598. sectionNumber 
  599. startSection 
  600. markSection 
  601. /"Table 
  602. Contents"
  603. record 
  604. Exit 
  605. selected 
  606. sent 
  607. Command 
  608. started 
  609. . If so, 
  610. Tour.
  611.     linkDLL "tbkwin.dll"
  612.         STRING GetWinIniVar(
  613. OldBook 
  614. ","AppSampPath")
  615. "Unable 
  616. G    New 
  617. , issue a warning 
  618.  creating a 
  619. 8will 
  620. -- impossible 
  621. "Creating a 
  622. Pmean 
  623. can't 
  624. " && \
  625. unless 
  626. directly." \
  627. f"Create" 
  628. "Cancel"
  629.  opening a 
  630. "Opening a 
  631. " && \
  632. -- Use 
  633. function 
  634. asterisk, 
  635. strip x
  636. SPACE & TAB & "*" & CR & LF
  637. restoreEnvironment
  638. enterPage
  639. author
  640. leavePage
  641. leaveBook
  642. enterBook
  643. strip
  644. author
  645. myAuthor
  646. Title
  647. Welcome
  648. enterBook
  649. reader
  650. eRrestoreEnvironment
  651. sizeToPage
  652. The hierarchy 2
  653. s_launchedFrom
  654. s_changesDB
  655. s_currentSection
  656. leaveBook
  657. eRrestoreEnvironment
  658. s_changesDB
  659. restoreEnvironment
  660. oldChangesDB
  661. oldFromAppSampler
  662. oldLaunchedFrom
  663. s_launchedFrom
  664. s_changesDB
  665. sFromAppSampler
  666. enterPage
  667. sectionNumber
  668. startSection
  669. sectionNumber
  670. markSection
  671. Table of Contents
  672. default
  673. s_sectionStarted
  674. leavePage
  675. sectionNumber
  676. s_currentSection
  677. tbkwin.dll
  678. GetWinIniVar
  679. ToolBook
  680. AppSampPath
  681. GetWinIniVar
  682. AppSamp.tbk
  683. Unable to return to the Application Sampler.
  684. OldBook
  685. sFromAppSampler
  686. Creating a new book will mean you can't return
  687. to the Application Sampler unless you open it directly.
  688. Create
  689. Cancel
  690. Cancel
  691. sFromAppSampler
  692. Opening a new book will mean you can't return
  693. to the Application Sampler unless you open it directly.
  694. Cancel
  695. Cancel
  696. sFromAppSampler
  697. strip
  698. Popping items from a list
  699. sectionNumber
  700.     The objects property of a page, background, or group returns a list of object references. The object property of an object is the object's type (e.g. the object of ellipse id 42 is ellipse). Using the pop command and the objects and object properties, you can write a handler to count the number of objects of a certain type on a page.
  701. 1.    Create a button called "Count Ellipses"
  702. 2.    Write a handler that gets the objects property of this page. Then, using the pop command, count the number of objects that are ellipses.
  703.     Switch to Reader level and click the "Hint" button for one solution.
  704. 3.    How could you count all the rectangles on the page?
  705. Popping items from a listttttttttttter o
  706.  to handle buttonUp
  707.         set numEllipse to 0
  708.          get objects of this page
  709.         while it is not null
  710.             pop it into anObject
  711.             if object of anObject is "ellipse"
  712.                 increment numEllipse
  713.             end
  714.         end
  715.         put "Number of ellipses is" && numEllipse
  716. end buttonUp
  717. -- Show 
  718. the hint.
  719. "Hint"
  720. buttonUp
  721. buttonUp
  722. Accessing items in lists
  723. sectionNumber
  724.     Many properties are lists. For example, fillColor, strokeColor and bounds are all lists. In this exercise you will see how to change an item in an object's bounds to change the object's height.
  725. 1.    Look at the script in the button "Shorten Pyramid."
  726.     Double-click the button while pressing the Ctrl key. Notice which item of the pyramid's bounds is modified by the script.
  727. 2.    Switch to Reader level and click several times on the "Shorten Pyramid" button. What happens?
  728. 3.    Create a new button called "Grow Pyramid" and write a buttonUp handler to make the pyramid taller by moving the bottom of the pyramid down...............
  729. Accessing items in lists
  730. Shorten Pyramid
  731. Pyramid
  732. -- Make the 
  733. "e" shorter 
  734. units 
  735. Hincrementing 
  736. =. The 
  737. -- corresponds 
  738. (y coordinate) 
  739. Ledge.
  740. "pyramid"
  741. buttonUp
  742. buttonUp
  743. pyramid
  744. pyramid
  745. Using OpenScript Help
  746. 226,280
  747. SetWinHelpDims
  748.     -- Adjust 
  749.  .ini settings 
  750. xrunning yet, so that 
  751. will come 
  752. )a good
  753. OpenScript 
  754. Kbar 
  755.     -- below default 
  756. OWorkBk 
  757.     -- Note: Assumes most common 
  758. M,which 
  759. standard VGA,
  760.  3.0 
  761.  compatibility.
  762.     linkDLL "tbkwin.dll"
  763.         WORD SetWinIniVar(STRING,
  764. "Windows 
  765. ","Xl","27")
  766. ","Yu","37")
  767. ","Xr","611")
  768. ","Yd","475")
  769. ","Maximized","0")
  770. enterpage
  771. SetWinHelpDims
  772. enterpage
  773. SetWinHelpDims
  774. SetWinHelpDims
  775. tbkwin.dll
  776. SetWinIniVar
  777. Windows Help
  778. SetWinIniVar
  779. Windows Help
  780. SetWinIniVar
  781. Windows Help
  782. SetWinIniVar
  783. Windows Help
  784. SetWinIniVar
  785. Windows Help
  786. Maximized
  787. SetWinIniVar
  788. sectionNumber
  789.     In this exercise you will display and explore OpenScript Help. Follow the steps below. Please read all the instructions before starting.
  790. 1.    Activate the Command window.
  791.     Display the Command window by pressing Shift+F3. You can move the Command window by dragging its caption bar. If the Command window is already visible, click it to activate it.  
  792. 2.    Display OpenScript Help: Press the F1 key.
  793. 3.    Click "Using this Encyclopedia" in the index and read the text displayed. Return to the index and explore other terms of interest. When you are finished, close OpenScript Help by double-clicking its Control menu.
  794.     For information about using Windows help itself, choose "Using Help" from the Help menu in OpenScript Help.
  795.  Help.
  796. Using OpenScript Help
  797. What this book contains
  798. What this book contains
  799. This book contains exercises and examples to help you learn to use OpenScript for writing scripts. The book is divided into chapters and sections. Each section covers one topic and contains a mix of explanation and exercises. 
  800. Chapter
  801. Explana-
  802. Exercise
  803. Explana-
  804. Exercise
  805. Section
  806. Section
  807. startSection
  808. sectionNumber
  809. User-defined functions 2
  810. ontinue
  811. User-defined functions, continued
  812. sectionNumber
  813. The following OpenScript command uses the isAlpha function to set the variable charType to true or false:
  814. set charType to isAlpha(char 2 of name)
  815. If a function is not defined in the same script as the handler that refers to it, ToolBook follows the object hierarchy looking for a corresponding to get handler.r.ect hierarchy looking for a matching to get handler.ndler..ollows the object hierarchy to find a matching to get handler.
  816. Object Types
  817. OpenScript Help
  818. Clicking a page
  819. Writing a Simple buttonUp handle
  820. Restoring Menus
  821. Listing objects, continued
  822. .    Toolbook programming
  823. To set handler continued
  824. ith a 
  825. sectionNumber
  826. 1.    Read about to set handlers in OpenScript help.
  827. 2.    Write a to set handler to set a property called objectSize of the green ellipse to the right. Place the handler in the ellipse's script.
  828. 3.    Test the handler from the Command window by typing:
  829.     set the objectSize of ellipse "green" to 2000, 500
  830.     To see one solution, switch to Reader level and click the "Hint" button.r level and click the "Hint" button..
  831. To set handler, continuedwith a To Set Handler, cont.
  832. green
  833. -- Get and Set handlers for the size property.
  834. -- Place them in an object's script.
  835. to set objectSize to xyList
  836.     get my bounds
  837.     set item 3 of it to item 1 of it + item 1 of xyList
  838.     set item 4 of it to item 2 of it + item 2 of xyList
  839.     set my bounds to it
  840. to get objectSize
  841.     get my bounds
  842.     clear theSize
  843.     push item 4 of it - item 2 of it onto theSize
  844.     push item 3 of it - item 1 of it onto theSize
  845.     return theSize
  846. -- Show 
  847. the hint.
  848. "Hint"
  849. buttonUp
  850. buttonUp
  851. Branching control structures
  852. ranching
  853. If/then/else and conditions/when/else are ToolBook's branching control structures. If/then/else provides two-way branching and Conditions/when/else provides many way.....vides many way.....
  854. to handle buttonUp
  855.     ask "What's your name?"
  856.     if it is not null then
  857.         set text of field "Name" to it
  858.     else
  859.         beep 10
  860.     end if
  861. endep 10
  862.     end if
  863. to handle buttonUp
  864.     request "How Hot?" with "Mild" or \
  865.         "Medium" or "Hot"
  866.     conditions
  867.         when it is "Mild"
  868.             set spice to 0
  869.         when it is "Medium"
  870.             set spice to 5
  871.         else
  872.             set spice to 10
  873. If/then/else:
  874. Conditions/when/else:
  875. sectionNumber
  876. Branching control structuresgggggggggggg
  877. User-defined functions 1
  878. ntinue
  879. User-defined functions, continued
  880. An example of a user-defined function is:
  881. to get isAlpha testChar
  882.     return testChar is in "abcdefghijklmnopqrstuvwxyz" 
  883. The name of this function is "isAlpha". It has one parameter, "testChar". The return command sets the function's value to true it testChar is a letter or false if it is not.
  884. tter.
  885. Sets the variable charType to true or false
  886. sectionNumber
  887. Looping control structures
  888. sectionNumber
  889. Looping control structuresgggggggggg
  890. Step, do/until, and while are ToolBook's looping control structures......tep            - repeats 
  891. to handle buttonUp
  892.     step i from 1 to 10
  893.         set fieldName to "field " & i
  894.         clear the text of field fieldName
  895. end1 seconds
  896. end    beep 10
  897.     end if
  898. Step:
  899. to handle buttonUp
  900.     set giveAccess to false
  901.     while not giveAccess
  902.         ask "Password"
  903.         if it is securityCode of this book then
  904.             set giveAccess to true
  905.         end if
  906. endndnd
  907. While:
  908. to handle buttonUp
  909.         pop objectList
  910.         show it
  911.     until objectList is null
  912. endd"
  913.     if it is securityCode of this book then
  914.         put true into giveAccess
  915.     end if
  916. Do/until:
  917. The sysCursor property
  918. sectionNumber
  919.     The ToolBook system also has properties. They are called system properties. One of many useful system properties is the sysCursor property which can be used to change the shape of the mouse pointer.
  920. 1.    The "Please Wait" button contains the script displayed at the bottom of the page. Look at the script and try to identify the commands that change the sysCursor property.
  921. 2.    Switch to Reader level and click the button to see how the cursor shape is changed.
  922. 3.    Look up sysCursor in OpenScript Help and edit the button's script to try some of the other cursor shapes.....ursor shapes. shapes..es..s.rsor shapes..
  923. The sysCursor property
  924. Please Wait
  925. -- Set the cursor 
  926. hourglass 
  927. default shape.
  928. buttonUp
  929. buttonUp
  930. Please Wait
  931. -- Shows setting the cursor to a different shape
  932. to handle buttonUp
  933.     set sysCursor to 4
  934.     pause 3 seconds
  935.     set sysCursor to 1
  936. Handlers in backgrounds
  937. sectionNumber
  938. If neither the object nor the page has a buttonDown handler, but the background does, the background handler gets executed and the message stops.tops.
  939. Handlers in backgrounds
  940. Spark
  941. height
  942. height
  943. bkgnd script
  944. to handle buttonDown
  945.     beep 10
  946. to handle myMessage
  947.     go to page "Test"
  948. arrow
  949. -- Animate the message demo 
  950. showMe
  951. moveLSpark "et1"
  952. "bkgnd 
  953. showMe
  954. showMe
  955. moveLSpark
  956. moveLSpark
  957. moveLSpark
  958. bkgnd script
  959. bkgnd script
  960. bkgnd script
  961.     The special variable It is used
  962.     as a default container in 
  963.     OpenScript. Whenever you 
  964.     use a get command, 
  965.     OpenScript places the 
  966.     result in the variable It.
  967.     Ask and request commands 
  968.     also store their results in It.
  969.     For this exercise, each line in the "Commands" field is an OpenScript command that affects or uses the value of the variable It. The field's script executes each line as you click it at Reader level and shows the resulting value of It in the field labeled "Value of It:"
  970. 1.    Switch to Reader level and click each command. Observe how the command affects the value of It...t.f IT.alue of IT.e value of IT.........
  971. Stuff
  972. T'was brillig and the slithy toves did gyre and ...eeeeeeeeeeeeeeeeee
  973. Field Stuff
  974.  h    B!
  975. T'was brillig and the slithy toves did gyre and ...bal in the wabe
  976. to handle buttonUp
  977.     get the text of field "stuff"
  978.     if it contains "brillig" then
  979. end buttonUp
  980. ITCommands
  981. -- Execute a 
  982. "itValue" 
  983. place the resulting value 
  984. special 
  985. ^"It" 
  986. lineNum 
  987. buttonUp
  988. buttonUp
  989. itValue
  990. textFromPoint
  991. itValue
  992. lineNum
  993. get the text of field "Stuff"
  994. put it
  995. get (10 * 15)
  996. request it with "OK" or "Cancel"
  997. request it with "Yes" or "No"
  998. itValue
  999. Value of It:
  1000. Commands:
  1001. T'was brillig and the slithy toves did gyre and ...
  1002. sectionNumber
  1003. Forwarding a message
  1004. sectionNumber
  1005. If a handler contains a forward statement, the message is passed on to the next object in the hierarchy.y
  1006. Forwarding a message
  1007. Spark
  1008. height
  1009. height
  1010. arrow
  1011. bkgnd script
  1012. to handle buttonDown
  1013.     beep 10
  1014.     forward
  1015. to handle myMessage
  1016.     go to page "Test"
  1017. forward
  1018. -- Animate the message demo 
  1019. showMe
  1020. moveLSpark "et1"
  1021. "bkgnd 
  1022. showMe
  1023. showMe
  1024. moveLSpark
  1025. moveLSpark
  1026. moveLSpark
  1027. bkgnd script
  1028. bkgnd script
  1029. forward
  1030. moveLSpark
  1031. moveLSpark
  1032. forward
  1033. bkgnd script
  1034. More on forward
  1035. -- Animate the message demo 
  1036. showMe
  1037. moveLSpark "et1"
  1038. "bkgnd 
  1039. showMe
  1040. showMe
  1041. moveLSpark
  1042. button script
  1043. button script
  1044. button forward
  1045. moveLSpark
  1046. moveLSpark
  1047. bkgnd script
  1048. background forward
  1049. moveLSpark
  1050. book script
  1051. book script
  1052. book script
  1053. background forward
  1054. bkgnd script
  1055. bkgnd script
  1056. button forward
  1057. button script
  1058. sectionNumber
  1059. Objects further up in the hierarchy will handle a forwarded message if the objects have a handler for the message..
  1060. More on forward.
  1061. Spark
  1062. height
  1063. height
  1064. bkgnd script
  1065. to handle buttonDown
  1066.     forward
  1067.     beep 10
  1068. to handle myMessage
  1069.     go to page "Test"
  1070. background forward
  1071. book script
  1072. to handle buttonDown
  1073.     beep 30
  1074. the target to true
  1075.     set invert of the target to false
  1076. to handle myMessage
  1077.     go to page "Test"
  1078. button script
  1079. to handle buttonDown
  1080.     beep 10
  1081.     forward
  1082. endddd myMessage
  1083.     go to page "Test"
  1084. end"Test"
  1085. button forward
  1086. arrow
  1087. Background objects
  1088. sectionNumber
  1089. If you click an object located on the background, the object gets the message first. If the object doesn't have a handler for the message, the message passes to the background and so on.so on.
  1090. Background objectskground
  1091. Spark
  1092. height
  1093. height
  1094. arrow
  1095. -- Animate the message demo 
  1096. showMe
  1097. moveLSpark "bt1"
  1098. showMe
  1099. showMe
  1100. moveLSpark
  1101. moveLSpark
  1102. moveLSpark
  1103. moveLSpark
  1104. Clicking a page
  1105. sectionNumber
  1106. If you click the page, but away from any object, the message goes directly to the page.oes directly to the page.
  1107. Clicking a pageege
  1108. Spark
  1109. height
  1110. height
  1111. arrow
  1112. -- Animate the message demo 
  1113. showMe
  1114. moveLSpark "pgt"
  1115. "et5"
  1116. showMe
  1117. showMe
  1118. moveLSpark
  1119. moveLSpark
  1120. moveLSpark
  1121. moveLSpark
  1122. Objects in groups
  1123. -- Animate the message demo 
  1124. showMe
  1125. moveLSpark "et1"
  1126. showMe
  1127. showMe
  1128. moveLSpark
  1129. moveLSpark
  1130. moveLSpark
  1131. moveLSpark
  1132. moveLSpark
  1133. moveLSpark
  1134. sectionNumber
  1135. If you click an object in a group, the message goes first to the object, then to the group, then to the parent of the group (in this example, the page), and so on until the message is handled or until it reaches the ToolBook system.
  1136. Objects in groupss
  1137. Spark
  1138. height
  1139. height
  1140. arrow
  1141. The UniqueName
  1142. Basic concepts
  1143. hical Naviga
  1144. Objects in Groups
  1145. The object hierarchy
  1146. User-defined functions continue
  1147. Listing objects using push and p
  1148. sectionNumber
  1149.     The objective in this exercise is to write a handler to display the names or IDs of all the objects on a page, even if they are nested in groups. One technique is to use the push and pop commands. The basic steps for listing objects on the page are as follows:
  1150. A.    Get the value of the objects property for the page (a list of objects).
  1151. B.    Pop an item from the list:
  1152.         If the item identifies an object, not a group 
  1153.             display that object's name or ID
  1154.         otherwise, if the item identifies a group
  1155.             get the objects of the group
  1156.             push the objects onto the list of objects
  1157. C.     Repeat step B until the list is empty.
  1158.     Continued on the next page.ge. page. page.
  1159. Listing objects using push and pop
  1160. "Sample1"
  1161. Button Indic
  1162. group indic
  1163. Group
  1164. "2    6#
  1165. group indic
  1166. Group
  1167. The objects property of page "sample1" is the list of objects whose parent is the page. page.round.
  1168. Chapter Head
  1169. Click the right arrow to continue.rrrrrrrrr
  1170. Title
  1171. Table of Contents
  1172. -- Go 
  1173. the Table 
  1174. Contents 
  1175. buttonUp
  1176. buttonUp
  1177. Table of Contents
  1178. Table of Contents
  1179. -- If 
  1180. moved 
  1181. reposition 
  1182. on the 
  1183. -- user-defined property, home, 
  1184. /graphic covering 
  1185. -- When 
  1186. qmouse 
  1187. pressed, 
  1188. released, 
  1189. w. Finally, 
  1190. -- Move 
  1191. -- depending on 
  1192. parameter, x, which can be 
  1193. H15,15
  1194. buttonDown
  1195. moved
  1196. buttonUp
  1197. press
  1198. moved
  1199. buttonDown
  1200. press
  1201. buttonUp
  1202. press
  1203. previous
  1204. press
  1205. 7755,5480
  1206.      
  1207. Right
  1208. -- If 
  1209. moved, 
  1210. a user-defined property, home, 
  1211. -- the 
  1212. graphic covering 
  1213. -- When 
  1214. Bmouse 
  1215. pressed, 
  1216. released, 
  1217. w. Finally, 
  1218. -- Move 
  1219. -- depending on 
  1220. parameter, x, which can be 
  1221. H15,15
  1222. buttonDown
  1223. moved
  1224. buttonUp
  1225. press
  1226. moved
  1227. buttonDown
  1228. press
  1229. buttonUp
  1230. press
  1231. press
  1232. 8370,5475
  1233.      
  1234. Object types
  1235. -- Place the type 
  1236. {clicked 
  1237. "Type" 
  1238. Glocation
  1239. objectFromPoint(
  1240. "Object 
  1241. buttonup
  1242. buttonup
  1243. Object Type
  1244. Object Type
  1245. location
  1246. sectionNumber
  1247.     This page contains a script that will display the object type of an object you click.
  1248. 1.    Switch to Reader level.
  1249.     Use F3 or the Reader command from the Edit menu. If you're not at Reader level the script cannot function.
  1250. 2.    Click different objects on the page and observe the type displayed in the 
  1251.     field at the bottom of the page.
  1252.     Note: this exercise only shows information about objects on the page. It will not show information about background objects.
  1253. 3.    Switch back to Author level and create an object of your own. Switch to Reader level and click your new object.
  1254.     Was the result what you expected?he result what you expected?
  1255. Object types
  1256. Object Type
  1257. Object Type
  1258. User-Defined Messages
  1259. Typing multiple commands in the
  1260. An Object's Location
  1261. Building Expressions
  1262. More on forward
  1263. Typing multiple commands in the 
  1264. A user-defined function for sort
  1265. Elements of OpenScript
  1266. Handler placement
  1267. sectionNumber
  1268. startSection
  1269. Handler placement
  1270. Remember, if an object doesn't have a handler for a message, the message continues up the object hierarchy. You can often simplify an application by placing a single handler further up in the hierarchy that handles messages for similar objects. Such a handler can use the target system property to identify the object that first received the message.
  1271. The following exercise shows how placing a handler further up in the hierarchy can reduce the number of handlers needed.eded.
  1272. User-defined functions
  1273. startSection
  1274. sectionNumber
  1275. OpenScript has numerous built-in functions for calculating arithmetic, statistical, string, and other results. You can create your own functions by writing a special type of handler, called a "to get" handler.
  1276. Unlike a message handler, which runs in response to a message, a to
  1277. get handler runs only when its name is used in an OpenScript command.
  1278. mmand.
  1279. to area(self)
  1280. Area is a function that returns a the areArea is a function that returns a the arerens a the aren that returns a the are
  1281. User-defined functions
  1282. A self-correcting object
  1283. sectionNumber
  1284.     This exercise uses the Command window and shows how you can create a user-defined property to store an object's size.
  1285. 1.    Activate the Command window. Create a property called "originalSize" and set it to the bounds of the triangle by typing:
  1286.     set originalSize of polygon "triangle" to bounds 
  1287.         of polygon "triangle"
  1288. 2.    Select and resize the triangle, then type:
  1289.     set bounds of polygon "triangle" to originalSize 
  1290.         of polygon "triangle"
  1291. 3.    Display the value of the originalSize property in the Command window.
  1292.     Type: originalSize of polygon "triangle"""n "triangle"angle"then type:
  1293.         set bounds of polygon "triangle" to 
  1294.         originalSize of polygon "triangle"
  1295. A self-correcting objectc
  1296. triangle
  1297. Object names
  1298. -- Place the 
  1299. p, type 
  1300. {clicked
  1301. fields on 
  1302. . If 
  1303. 2mouse 
  1304. % but 
  1305. 1will be cleared.
  1306. Glocation
  1307. objectFromPoint(
  1308. "Object Name" 
  1309. Type" 
  1310. 0UniqueName" 
  1311. buttonup
  1312. buttonup
  1313. Object Name
  1314. Object Type
  1315. Object UniqueName
  1316. Object Name
  1317. Object Type
  1318. Object UniqueName
  1319. location
  1320. sectionNumber
  1321.     This page contains a script that will put the name, type, and uniqueName of any object you click into the fields at the bottom of the page.
  1322. 1.    Switch to Reader level.
  1323.     Use F3 or the Reader command from the Edit menu. The script cannot function at Author level.
  1324. 2.    Click each object on the page and observe the name, type, and uniqueName displayed.
  1325.     Note: this exercise will only show information about objects on the page. It will not show information about background objects.
  1326. 3.    Switch to Author level and create an object of your own. Return to Reader level and click your new object.
  1327.     Was the result what you expected??????????????
  1328. Object names
  1329. Object Name
  1330. Nameeeeeeee
  1331. Object Type
  1332. Object UniqueName
  1333. Unique Name
  1334. Red Square
  1335. Diamond
  1336. Pie Slice
  1337. Button
  1338. Hi There!
  1339. A user-defined function for chec
  1340. sectionNumber
  1341.     In this exercise, you will write a handler that defines a function that checks a character to see if it is a numeral.
  1342. 1.    Edit the script of this page and create a to get handler for a function called isNumber. The function should check a character supplied as a parameter and return true if the character is a numeral (0-9), or false if the character is not a numeral.
  1343.     This function is similar to the isAlpha function. For a hint click the "Hint" button.
  1344. 2.    Test the isNumber function by typing the following in the Command window:
  1345.     isNumber("3")
  1346.     isNumber("a")
  1347.     isNumber("a")
  1348.     isNumber("a")
  1349. A user-defined function for checking character type
  1350. to get isNumber testChar
  1351.         return testChar is in "0123456789"
  1352. -- Show 
  1353. the hint.
  1354. "Hint"
  1355. buttonUp
  1356. buttonUp
  1357. Local versus system variables
  1358. -- When leaving 
  1359. [the "totalSys" 
  1360. "totalLocal" 
  1361. -- fields.
  1362. 4count
  1363. leavePage
  1364. leavePage
  1365. totalLocal
  1366. totalSys
  1367. count
  1368. sectionNumber
  1369.     OpenScript has two types of variables: system and local. System variables retain their value when a handler has finished and can be shared between handlers. Local variables are discarded.
  1370.     In this example the two buttons, "System" and "Local", contain the scripts displayed below them. The scripts are identical except for the system declaration in one compared to the local declaration in the other.
  1371.     Each time one of the buttons is clicked, the value in the variable count is incremented and displayed in the total field.
  1372. 1.    Switch to Reader level and try clicking the buttons. How do they act differently??y???? do they act differently??????
  1373. Local versus system variables
  1374. to handle buttonUp
  1375.     system count
  1376.     if count is null then
  1377.         set count to 0
  1378.     increment count
  1379.     set the text of field "totalSys" to count
  1380. System
  1381. -- Increment the 
  1382. ^"count" 
  1383. display 
  1384. result
  1385. %"totalSys" 
  1386. . The 
  1387. ^, so its value remains 
  1388. ghandler 
  1389. finished 
  1390. -- running.
  1391. buttonUp
  1392. buttonUp
  1393. totalSys
  1394. count
  1395. System
  1396. totalSys
  1397. System Variable:
  1398. to handle buttonUp
  1399.     local count
  1400.     if count is null then
  1401.         set count to 0
  1402.     increment count
  1403.     set the text of field "totalLocal" to count
  1404. Local
  1405. -- Increment the 
  1406. ^"count" 
  1407. display 
  1408. result
  1409. %"totalLocal" 
  1410. . The 
  1411. ^, so its value 
  1412. discarded 
  1413. Fhandler 
  1414. -- finished running.
  1415. buttonUp
  1416. buttonUp
  1417. totalLocal
  1418. count
  1419. Local
  1420. totalLocal
  1421. Local Variable::
  1422. Setting an object's size with a 
  1423. sectionNumber
  1424.     An object's bounds property is a built-in property that contains coordinates of the upper left and lower right corners of the object's bounding rectangle. The size of the object (width and height) can be calculated by subtracting the left coordinate from the right and the top from the bottom. The size of an object can be set by adding the width and height to the left and top coordinates. 
  1425.     In this exercise you'll write a to set handler to set the size of an ellipse. After adding the handler to the object's script you should be able to type "set the objectSize of ellipse green to 800,300" in the Command window to change the object's size and have its bounds change accordingly.
  1426.     Continued on the next page.
  1427. ext page.
  1428. 1.    Read about to get and to set handlers in the Using OpenScript manual.
  1429. 2.    Following the guidelines above write handlers
  1430. Setting an object's size with a to set handler
  1431. Verifying data during input with
  1432. sectionNumber
  1433.     In this example you will write a keyChar handler to allow only numerals to be typed in the Number field shown to the right.
  1434. 1.    Look up the keyChar message in OpenScript help.
  1435. 2.    Try to write a keyChar handler in the script of the "Number" field to the right that allows only numerals to be typed.
  1436.     Hint: If a character from 0 to 9 is typed, the message should be forwarded. Otherwise, the handler should beep and do nothing. Test the handler by switching to Reader level then typing in the field.
  1437.     To see one solution, switch to Reader level and click the "Hint" button.....el and click the "Hint" button.
  1438. Verifying data during input with a keyChar handler
  1439. to handle keyChar key
  1440.     get ansiToChar(key)
  1441.     if it is in "0123456789" then
  1442.         forward
  1443.     else
  1444.         beep 5
  1445.     end if
  1446. end end if
  1447. -- Show 
  1448. the hint.
  1449. "Hint"
  1450. buttonUp
  1451. buttonUp
  1452. Number:
  1453. Branching with conditions
  1454.     The conditions/when/else control structure  allows you to accomodate many conditions in one structure.
  1455. 1.    Create a button.
  1456. 2.    Edit the button's script to use the request command to request a color: Light, Medium or Dark. Then, using the conditions control structure, set the button's fillColor to "White", "Cyan", or "Red" according to the chosen value.
  1457.     For one solution, switch to Reader level and click the "Hint" button.
  1458. 3.    Test your button by clicking it at Reader level.
  1459. Branching with conditions
  1460. to handle buttonUp
  1461.     request "Which color?" with "Light" or \
  1462.         "Medium" or "Dark"
  1463.     conditions
  1464.         when it is "Light"
  1465.             set my fillColor to White
  1466.         when it is "Medium"
  1467.             set my fillColor to Cyan
  1468.         when it is "Dark"
  1469.             set my fillColor to Red
  1470. enddddd
  1471. -- Show 
  1472. the hint.
  1473. "Hint"
  1474. buttonUp
  1475. buttonUp
  1476. sectionNumber
  1477. Changing an object's bounds
  1478. sectionNumber
  1479.     Another of an object's properties is its bounds. The bounds of an object is a list of four numbers representing the coordinates (x,y) of the upper left corner and lower right corner of a rectangle bounding the object. In this exercise you'll write a handler to change the bounds of the smiley face, which is a group.
  1480. 1.    Look at the script of the "Flat Face" button. Also look at the script of the "Round Face" button.
  1481.     Select the button and use the Button Properties command or hold down the Ctrl key and double-click the button with the selection arrow. Notice the command that changes the bounds of the "Smiley" group.
  1482. 2.    Switch to Reader level and click each of the buttons.
  1483. ttons.
  1484. button to try it out.
  1485. Changing an object's bounds
  1486. Smiley
  1487. Round Face
  1488. Flat Face
  1489. -- Return the 
  1490. "Smiley" 
  1491. its original 
  1492. 5776, 837, 7998, 3162
  1493. buttonUp
  1494. buttonUp
  1495. Smiley
  1496. -- Change the 
  1497. "Smiley" 
  1498. looks flat
  1499. 5776, 837, 7998, 1500
  1500. buttonUp
  1501. buttonUp
  1502. Smiley
  1503. Restoring menus
  1504.     Adding or deleting menus and menu items from the menu bar changes the menu until you change it back--even if you open another book. You can restore the menu bar to the ToolBook default by using the restore menubar command.
  1505. 1.    Type the following command in the Command window:
  1506.     restore menubar at both
  1507.     You can ensure that your menu bar is restored whenever you open a new book by adding a leaveBook handler to the script of any book that changes the menu. See the handler on the right for an example.
  1508. xamples.
  1509. Restoring menus
  1510. -- leaveBook handler to restore the menu
  1511. -- bar when going to another book.
  1512. to handle leaveBook
  1513.         restore menuBar at both
  1514. -- leavePage handler to restore the menu
  1515. -- bar when going to another page.
  1516. to handle leavePage
  1517.         restore menuBar at both
  1518. sectionNumber
  1519. Topic
  1520. Branching with If/then/else
  1521. sectionNumber
  1522.     The if/then/else control structure allows you to test a condition and do different things as a result. In this exercise you will use if/then/else to test the results of an ask command.
  1523. 1.    Edit the "Set Attendance" button's script and create a buttonUp handler. In the handler, ask for the attendance. Check the result to see if it is between 0 and 10. If it isn't, beep. If it is, set the text of field "Attendance" to the value.
  1524.     To see one solution, switch to Reader level and click the "Hint" button (click again to make the hint disappear).
  1525. 2.    Try the script by clicking the "Set Attendance" button...on.ld's scripts and switch to Reader level. el.     l. 
  1526. Branching with If/then/else
  1527. Attendance
  1528. Attendance
  1529. to handle buttonUp
  1530.     ask "Attendance?"
  1531.     if it >=0 and it <= 10 then
  1532.         set text of field "Attendance" to it
  1533.     else
  1534.         beep 20
  1535.     end if
  1536. endddddd
  1537. Set Attendance
  1538. -- Show 
  1539. the hint.
  1540. "Hint"
  1541. buttonUp
  1542. buttonUp
  1543. Containers
  1544. Changing an Object's Bounds
  1545. The hierarchy 2
  1546. Drawing Objects from a Script
  1547. To set handler continued
  1548. Listing objects continued
  1549. and P
  1550. sectionNumber
  1551.     In this exercise you will write a handler that displays the name or ID of all the objects on a page. To prepare, look at OpenScript Help for information on the objects and object properties.
  1552. 1.    Create a button and write a handler for it that will display the names or IDs of objects on the page in the "Object List" field to the right.
  1553.     To see one solution, switch to Reader level and click the "Hint" button. You can cut and paste this handler into the field's script and then experiment by making modifications. The handler can be modified in numerous ways such as displaying information about object properties for each object or indenting objects in groups.ps..ng objects in groups.. groups.
  1554. Listing objects, continued
  1555. blank hint
  1556. to handle buttonUp
  1557.     clear text of field "Object List"
  1558.     set x to objects of this page
  1559.     while x is not null
  1560.         pop x
  1561.         put object of it && quote&name of it"e\
  1562.             & CRLF after text of field "Object List"
  1563.         -- For a group, push its objects back onto
  1564.         -- the list of objects to display
  1565.         if object of it is "group"
  1566.             push objects of it onto x
  1567.         end
  1568. end buttonUp
  1569. Object List
  1570. -- Show 
  1571. the hint.
  1572. "Hint"
  1573. buttonUp
  1574. buttonUp
  1575. Geometrics
  1576. Square
  1577. Triangle
  1578. Object List:
  1579. (    used
  1580.     true
  1581. Objects
  1582. sectionNumber
  1583. startSection
  1584. Objectssssssssss
  1585. A ToolBook book consists of objects such as buttons, fields, graphics, and pages. An author defines the objects, their properties, and their behavior. The book's reader interacts with the objects.
  1586. As an example, this page contains record fields (for text), several buttons, and various graphic objects.page also contains a foreground that could contain objects unique to this page.e to this page.
  1587. Objects
  1588. Handlers in Objects
  1589. Visual Effects
  1590. Properties
  1591. sectionNumber
  1592. startSection
  1593. Properties
  1594. Objects have properties. You can change an object's appearance or select different built-in ToolBook behaviors by changing the object's properties. You can add to or replace an object's built-in behavior by changing the object's script.
  1595. The following exercises show some examples of changing properties.
  1596. Properties
  1597. continue
  1598. A final note ...
  1599. Using the Ask Command
  1600. A Self-Correcting Object
  1601. Typing multiple commands in the 
  1602. sectionNumber
  1603.     You can type multiple commands in the Command window at the same time by separating them with semicolons.
  1604. 1.    Type the following commands in the Command window and press Enter when you're finished:
  1605.     step i from 1 to 100; move ellipse dot by 10,10;  end
  1606. 2.    What commands would you type to move the dot back to its starting point?
  1607. 3.    What commands would you type to move the dot back to its starting point?
  1608. Typing multiple commands in the Command window
  1609. Mouse movement and button messag
  1610. -- When leaving 
  1611. [the "Messages" 
  1612. leavePage
  1613. leavePage
  1614. Messages
  1615. sectionNumber
  1616.     Numerous messages are sent to an object as a result of mouse movement and actions. The messages are:
  1617.     mouseEnter            mouseLeave
  1618.     buttonDown               buttonUp
  1619.     buttonStillDown           rightButtonDown
  1620.     buttonDoubleClick        rightButtonUp
  1621.     rightButtonDoubleClick
  1622. 1.    Switch to Reader level
  1623.     Press F3. (mouse messages aren't sent at Author level).
  1624. 2.    As you move the mouse over the magenta rectangle and click, the messages sent to the rectangle will be displayed in the "Messages" field. Try to display each of the ones listed above..........
  1625. Mouse movement and button messagess
  1626. Messages
  1627. Messages:
  1628. Object drawing and display
  1629. Object drawing and display
  1630. OpenScript has commands to draw objects as well as to manipulate them in various ways. The following exercises use OpenScript commands to draw, show, hide, and move objects.nScript commands.ds.ving objects.
  1631. startSection
  1632. sectionNumber
  1633. Navigation and visual effects
  1634. sectionNumber
  1635. startSection
  1636. Navigation and visual effects
  1637. OpenScript has commands that you can use to navigate between pages and books. It also has commands that you can use to create different visual effects when switching pages. 
  1638. The following exercise looks at page navigation as well as the three special effects ToolBook provides.
  1639. Types of Objects
  1640. Branching with Conditions
  1641. Setting an Object's Size with a 
  1642. User-defined functions
  1643. FxZoom fxDissolve and fxWipe
  1644. A self-sorting field
  1645. sectionNumber
  1646. startSection
  1647. A self-sorting field
  1648. One of the powerful things about ToolBook's object-oriented approach is that you can design objects, complete with scripts, that can be cut and pasted into other applications. An example of this is a field that has a script to sort itself. Such a field could be pasted into other applications ready to go.
  1649. The following exercise shows how to create a self-sorting field.d.orting field.
  1650. A simple object browser
  1651. When a page or background has many objects, it can be difficult to keep track of what their names are, which ones have scripts and so on. One tool that can make it easy to inspect objects and their properties is a script that displays information on objects you click.
  1652. In the following exercise you will write a script that allows you to quickly see information about objects.jects..cts..bjects...cts.
  1653. startSection
  1654. sectionNumber
  1655. A simple object browser
  1656. Structure of a Handler
  1657. Another Example of the step cont
  1658. User-defined functions 1
  1659. Listing all objects on a page
  1660. sectionNumber
  1661. startSection
  1662. Listing all objects on a page
  1663. Backgrounds, pages, and groups all have an objects property. Its value is a list of all the objects of the background, page or group. Listing objects from the objects property is simple unless one of the objects is a group. This is because a group contains other objects. 
  1664. The following exercise shows an example of using the push and pop commands to list objects even if they are within groups.following exercise shows how to write a handler that lists the object type and name of objects on a page.............s on a page.page.n a page.......
  1665.  Contents
  1666. Showing all Objects on a Page
  1667. Table of Contents
  1668. Using the ask command
  1669. sectionNumber
  1670. 1.    Create a button and label it "Get First Name".
  1671.     Use the button tool from the tool palette.
  1672. 2.    Edit the button's script and type:
  1673.     to handle buttonUp
  1674.         ask "Type your first name" with "Sigmund"
  1675.         set the text of field "First Name" to it
  1676.     end buttonUp
  1677. 3.    Switch to Reader level and click the button.
  1678.     What happens when you click the Cancel button? What happens if you remove "with "Sigmund"" from the Ask command in the script??pt? if you remove the "with "Sigmund"" from the Ask command?
  1679. Using the ask commanddddd
  1680. First Name
  1681. First Namest Name
  1682. Structure of a handler
  1683. Structure of a handler
  1684. A handler has a beginning, middle, and end.
  1685. In the following exercise you will write a simple handler for a buttonUp message.ritten using OpenScript. The end is a line identifying the end of the handler.
  1686. In the following exercise you will 
  1687. write a simple buttonUp handler.you will write a simple buttonUp handler.
  1688. sectionNumber
  1689. -- Changes to reader level when
  1690. -- page is entered.
  1691. to handle enterPage
  1692.     send Reader
  1693. end enterPagerPageeeeee
  1694. Beginning: identifies the name of the message to which this handler responds.
  1695. Middle: contains instructions in OpenScript saying what to do when the message is received.
  1696. End: marks the end of the handler
  1697. ToolBook Programming
  1698. Name versus ID
  1699. Setting and Getting Field Text i
  1700. Handlers in Pages
  1701. A simple object browser using ri
  1702. Table of Contents
  1703. Chapters
  1704. Sections
  1705. -- Turn the 
  1706. selected section 
  1707. clicked.
  1708. turnToSection
  1709. pressed.
  1710.         -- 
  1711. pkey 
  1712. default processing
  1713. -- Algorithm:
  1714. -- Get 
  1715. currently 
  1716. . If 
  1717. named 
  1718. strip(
  1719. oselectedTextLines 
  1720. Click
  1721. buttonDoubleClick
  1722. keyChar
  1723. turnToSection
  1724. buttonDoubleClick
  1725. qturnToSection
  1726. keyChar
  1727. qturnToSection
  1728. turnToSection
  1729. strip
  1730. -- Display 
  1731. the help 
  1732. helpObject 
  1733. buttonUp
  1734. buttonUp
  1735. helpObject
  1736. Close the Workbook
  1737. -- Go 
  1738. same 
  1739. buttonUp
  1740. buttonUp
  1741. Close the Workbook
  1742. Title
  1743. -- Hide 
  1744. help 
  1745. clicked.
  1746. default
  1747. buttonDoubleClick
  1748. buttonDoubleClick
  1749. default
  1750. Click a chapter name on the left to see  that chapter's sections on the right.
  1751. Double-click a section name on the right to go to that section. As you complete each section or chapter, it will be marked with an asterisk beside its name.
  1752. Double-click this text to make it disappear
  1753. Chapter Name
  1754. Using the workbook
  1755. Using the workbook
  1756. startSection
  1757. sectionNumber
  1758. Exercise pages
  1759. Exercise pages
  1760. On exercise pages, ToolBook
  1761. automatically changes to Author
  1762. level so you must use 
  1763. <Ctrl>+arrow keys or commands 
  1764. from the Page menu to turn pages.
  1765. To complete an exercise, follow directions in the field on the left and use the space to the right as your work area.area..............
  1766. Instructions
  1767. Title
  1768. Exercise Page
  1769. startSection
  1770. sectionNumber
  1771. Table of Contents
  1772. Sections6
  1773.     A self-sorting field
  1774.     Listing all objects on a page
  1775.     A simple object Browser
  1776. Sections5
  1777.     User-defined properties
  1778.     User-defined messages
  1779.     Handler placement
  1780.     User-defined functions
  1781.     Handling keystrokes
  1782.     To get and to set handlers
  1783. Sections4
  1784.     The Command window
  1785.     Ask and request
  1786.     Control structures
  1787.     Object drawing and display
  1788.     Navigation and visual effects
  1789.     Push and pop
  1790.     Menus
  1791. Sections3
  1792.     Object identifiers
  1793.     Properties
  1794.     Containers
  1795.     Lists
  1796.     Expressions
  1797. Sections2
  1798.     Toolbook programming
  1799.     Objects
  1800.     Messages
  1801.     Handlers
  1802.     The object hierarchy
  1803. Sections1
  1804.     What this book contains
  1805.     Navigating in this book
  1806.     Exercise pages
  1807.     OpenScript Help
  1808.     A final note ...
  1809.     What this book contains
  1810.     Navigating in this book
  1811.     Exercise pages
  1812.     OpenScript Help
  1813.     A final note ... keystrokes
  1814.     To get and to set handlersers
  1815. Using the workbooktionsic concepts    Elements of OpenScript    OpenScript commands    Advanced topics    OpenScript applicatio
  1816. OpenScript Workbook
  1817.     Using the workbook
  1818.     Basic concepts
  1819.     Elements of OpenScript
  1820.     OpenScript commands
  1821.     Advanced topics
  1822.     OpenScript applicationssonsOpenScript applicationsions
  1823. OpenScript Help
  1824. e Help
  1825. OpenScript Helpne Help
  1826. ToolBook comes with an extensive online OpenScript encyclopedia called OpenScript Help. To read OpenScript Help, activate the Command window by clicking it or open a Script window, then press <F1>.
  1827. OpenScript Help works the same way as standard Windows Help so it is similar to online help in other Windows applications. following exercise you getript Help....
  1828. ing [
  1829. startSection
  1830. sectionNumber
  1831. A final note ...
  1832. A final note ...
  1833. The exercises in this book are just starting points. Feel free to pick and choose topics that seem interesting, explore on your own, and make up your own examples.
  1834. Now, click the forward arrow to begin learning about OpenScript or click the Table of Contents button to turn to the table of contents.
  1835. ny o%
  1836. startSection
  1837. sectionNumber
  1838. Developing ToolBook Applications
  1839. OpenScript applications
  1840. User-defined functions 2
  1841. The object hierarchy
  1842. sectionNumber
  1843. startSection
  1844. The object hierarchyy
  1845. When a message is sent to an
  1846. object, it travels up what's called
  1847. the object hierarchy until
  1848. the message locates 
  1849. a handler for itself or 
  1850. until the message
  1851. reaches the ToolBook 
  1852. system.
  1853. Object
  1854. Button Indic
  1855. ToolBook
  1856. System
  1857. stemstem
  1858. Background
  1859. Page 
  1860. Object
  1861. Button Indic
  1862. group indic
  1863. Group
  1864. "2    6#
  1865. group indic
  1866. Group
  1867. Object
  1868. Button Indic
  1869. group indic
  1870. Group
  1871. Message
  1872. Spark
  1873. l+height
  1874. Spark
  1875. ,height
  1876. Spark
  1877. .height
  1878. Spark
  1879. h/height
  1880. Spark
  1881. 0height
  1882. Spark
  1883. 2height
  1884. 3used
  1885. 3true
  1886. Using OpenScript Help
  1887. Welcome
  1888. Exercise Pages
  1889. Specifying Parts of Strings
  1890. Developing ToolBook applications
  1891. Developing ToolBook applications
  1892. Developing a ToolBook application usually begins with the user interface. You can lay out the buttons, fields and other objects, then develop scripts to make them behave the way you want. While traditional program development tends to be linear, ToolBook development is more flexible and modifications can be made and tested readily.
  1893. to kE
  1894. sectionNumber
  1895. Handlers
  1896. Handler Placement
  1897. Object Names
  1898. Navigation and Visual Effects
  1899. Using the Request Command
  1900. ion, cont.
  1901. The Command Window
  1902. ctures - Looping
  1903. fx destination
  1904. A buttonUp handler Higher in the
  1905. Containers
  1906. Containers
  1907. A container is anything in OpenScript that can hold a value. Containers can be properties, variables, the special variables It and sysError, or the Command window.
  1908. The following exercises demonstrate using local variables versus system variables and the special variable It. Properties are covered in another section..c.topic.
  1909. objeE
  1910. startSection
  1911. sectionNumber
  1912. Handling standard menu choices
  1913. sectionNumber
  1914.     In this exercise you will see a script that alters how ToolBook responds to the Author menu item. When you choose a menu item, ToolBook sends a message to the current page. The message name is the same as the menu item, but without spaces or special characters.
  1915. 1.    Switch to Reader level and choose Author from the Edit menu.
  1916.     Notice what happens.
  1917. 2.    Edit the script of this page and add the handler displayed to the right.
  1918.     Choose Page Properties from the Object menu.
  1919. 3.    Change to Reader level again and choose Author from the Edit menu.
  1920.     What's different this time?
  1921. Handling standard menu choices
  1922. script1
  1923. to handle author
  1924.         request "Switch to Author level?" \
  1925.             with "Yes" or "No"
  1926.       if it is "Yes"
  1927.             forward
  1928.       end if
  1929. end author
  1930. end author
  1931. e enterBook
  1932. --positions the workbook window
  1933.     set syslevel to author
  1934.     send sizeToPage
  1935. end enterBook
  1936. Author Handler
  1937. A popup definition using show an
  1938. sectionNumber
  1939.     In this exercise you will write scripts to hide and show a field that contains a hotword definition.
  1940. 1.    Double-click in the green field to begin editing its text. Select the bold word "score" in the text and make it a hotword.
  1941.     Choose the Create Hotword command from the Text menu or press Ctrl-W. To outline the hotword choose Show Hotwords from the Text menu.
  1942. 2.    Edit the script of the hotword and create a buttonUp handler that shows the field called "definition" (the white field).
  1943. 3.    Edit the script of field "definition" to hide itself when it is clicked (you can use the special term self in the hide command).
  1944. 4.    Switch to Reader level and try your scripts by clicking the fields. 
  1945. A popup definition using show and hidend Hideddddddddd
  1946. hotwords
  1947. Four score and seven years ago, our fathers brought forth a new nation, conceived in liberty and dedicated to the proposition that all men are created equal.
  1948. Definition
  1949. A score is twenty years. "Four score and seven" is eighty-seven years."ight-seven years."
  1950. -- Handler for the hotword
  1951. to handle buttonUp
  1952.       show field "definition"
  1953. end buttonUp
  1954. -- Handler for the popup definition
  1955. to handle buttonUp
  1956.       hide self
  1957. end buttonUp
  1958. -- Show 
  1959. the hint.
  1960. "Hint"
  1961. buttonUp
  1962. buttonUp
  1963. -- Add the message 
  1964. ppassed 
  1965. "msgText" parameter 
  1966. /"messages" 
  1967. . If its 
  1968. overflowing, 
  1969. A are added. Once 500 lines 
  1970. _ have accumulated, 
  1971. [them 
  1972. logMessage 
  1973. oldSuspend 
  1974.  & CRLF 
  1975. ) > 500 
  1976. -- Post 
  1977. names 
  1978. mouse 
  1979.  received 
  1980. buttonDown
  1981. mouseEnter
  1982. buttonStillDown
  1983. buttonUp
  1984. logMessage
  1985. buttonDoubleClick
  1986. rightButtonDown
  1987. mouseLeave
  1988. rightButtonUp
  1989. rightButtonDoubleClick
  1990. logMessage
  1991. messages
  1992. oldSuspend
  1993. msgText
  1994. mouseEnter
  1995. logMessage
  1996. mouseEnter
  1997. mouseLeave
  1998. logMessage
  1999. mouseLeave
  2000. buttonDown
  2001. logMessage
  2002. buttonDown
  2003. buttonStillDown
  2004. logMessage
  2005. buttonStillDown
  2006. buttonUp
  2007. logMessage
  2008. buttonUp
  2009. buttonDoubleClick
  2010. logMessage
  2011. buttonDoubleClick
  2012. rightButtonDown
  2013. logMessage
  2014. rightButtonDown
  2015. rightButtonUp
  2016. logMessage
  2017. rightButtonUp
  2018. rightButtonDoubleClick
  2019. logMessage
  2020. rightButtonDoubleClick
  2021. Working with objects from the Co
  2022. sectionNumber
  2023. 1.    Display the Command window.
  2024.     Press Shift+F3.
  2025. 2.    Type each of the following commands in the Command window. Press Enter after each command. 
  2026.     select ellipse "dot"
  2027.     unselect ellipse "dot"
  2028.     put position of ellipse "dot"
  2029.     move ellipse "dot" by 100,100
  2030.     set the fillColor of ellipse "dot" to green
  2031. set bounds of ellipse "dot" to 300,300,1300,1300
  2032.     edit the script of ellipse "dot"
  2033.     You can find out more about these commands in OpenScript Help.penScript manual.al.n the Using OpenScript manual. information on each command in the Using OpenScript manual."""""""""""""""""""""
  2034. Working with objects from the Command window
  2035. -- When the mouse 
  2036. pressed, 
  2037. released, 
  2038. buttonDown
  2039. buttonUp
  2040. buttonDown
  2041. 240,50,100
  2042. buttonUp
  2043. 60,50,100
  2044. Adding menus and menu items
  2045. sectionNumber
  2046.     The script to the right shows an example of adding a custom menu and menu items.
  2047. 1.    Edit the script of this page and type the handler displayed to the right.
  2048.     An easy way to do this is to type the following in the Command window:
  2049.     set script of this page to text of field "script1"
  2050. 2.    Install the menus by sending a setupMenu message to this page.
  2051.     Send the setupMenu message by typing the following in the Command window:
  2052.     send setupMenu
  2053. 3.    Try the new menu items.
  2054.     See the next exercise to restore the menu bar.
  2055.  Switch back to Author level.
  2056. Adding menus and menu items
  2057. script1
  2058. to handle setupMenu
  2059.     add menu"Script" at both
  2060.     add menuitem "Object" to menu "Script" at both
  2061.     add menuitem "Page" to menu "Script" at both
  2062.     add menuitem "Book" to menu "Script" at both
  2063.     deactivate menuitem "Object" at Reader
  2064. end setupMenu
  2065. to handle Object
  2066.     if the selection is not null
  2067.         edit the script of the selection
  2068.     end if
  2069. end Object
  2070. to handle Page
  2071.       edit the script of this page
  2072. end page
  2073. to handle book
  2074.       edit the script of this book
  2075. end book
  2076. to handle leavepage
  2077.       restore menubar at both
  2078. end leavepagee
  2079.       restore menubar at both
  2080. end leavepageeeeeeeeenubar at both
  2081. end leavepageepage leavepageepageleavepageepageepageepageepageepageeeeee
  2082. The uniqueName
  2083. sectionNumber
  2084. The uniqueName
  2085. An object's uniqueName identifies the object. It includes the object's ID, the page it is on and the name of the book it is in.
  2086. The following example shows you the name, object type, and uniqueName of several common objects.........ere the object is located.
  2087. The following example shows you the name, object type, and uniqueName of several common objects.
  2088. Forwarding a Message
  2089. age Hierarchy
  2090. Object Identifiers
  2091. The pattern property
  2092.     Another of an object's properties is its pattern property. This pattern is used to fill shapes.
  2093. 1.    Look up the pattern property using the Search button in OpenScript Help.
  2094.     Activate the Command window and press F1.
  2095. 2.    The button, "Watch", contains the script displayed at the bottom of this page. Examine the script and identify the line that sets the pattern property.
  2096. 3.    Switch to Reader level and click the "Watch" button.
  2097. 4.    Edit the button's script and add a line so that the pattern returns to solid after displaying the other patterns..erns.s.
  2098. The pattern propertyyyyyyyyyyyyyy of 
  2099. script1
  2100. -- Changes the pattern property of a rectangle
  2101. -- to all possible patterns.
  2102. to handle buttonUp
  2103.     step i from 1 to 128
  2104.         set pattern of rectangle "boob toob" to i
  2105. endddddddddddddd
  2106. Boob Toob
  2107. Watch
  2108. -- Change the 
  2109. property 
  2110. possible patterns.
  2111. "boob toob" 
  2112. buttonUp
  2113. buttonUp
  2114. boob toob
  2115. Watch
  2116. sectionNumber
  2117. Topic
  2118. ction
  2119. -- Switch 
  2120. Reader level 
  2121. entering 
  2122. enterBackground
  2123. enterBackground
  2124. Reader
  2125. Page Leader
  2126. Title
  2127. Table of Contents
  2128. -- Go 
  2129. the Table 
  2130. Contents 
  2131. buttonUp
  2132. buttonUp
  2133. Table of Contents
  2134. Table of Contents
  2135. -- If 
  2136. moved 
  2137. reposition 
  2138. on the 
  2139. -- user-defined property, home, 
  2140. /graphic covering 
  2141. -- When 
  2142. qmouse 
  2143. pressed, 
  2144. released, 
  2145. w. Finally, 
  2146. -- Move 
  2147. -- depending on 
  2148. parameter, x, which can be 
  2149. H15,15
  2150. buttonDown
  2151. moved
  2152. buttonUp
  2153. press
  2154. moved
  2155. buttonDown
  2156. press
  2157. buttonUp
  2158. press
  2159. previous
  2160. press
  2161. 7755,5480
  2162.      
  2163. Right
  2164. -- If 
  2165. moved, 
  2166. a user-defined property, home, 
  2167. -- the 
  2168. graphic covering 
  2169. -- When 
  2170. Bmouse 
  2171. pressed, 
  2172. released, 
  2173. w. Finally, 
  2174. -- Move 
  2175. -- depending on 
  2176. parameter, x, which can be 
  2177. H15,15
  2178. buttonDown
  2179. moved
  2180. buttonUp
  2181. press
  2182. moved
  2183. buttonDown
  2184. press
  2185. buttonUp
  2186. press
  2187. press
  2188. 8370,5475
  2189.      
  2190. Hiding and showing objects using
  2191. User-Defined Properties
  2192. Push and Pop
  2193. A popup definition using Show an
  2194. Handlers
  2195. sectionNumber
  2196. startSection
  2197. Handlerssandlerss
  2198. When an object receives a message, it can respond to the message or ignore it. If the object ignores the message, the message gets passed on to the group, page, background, or book that contains the object.
  2199. In order to respond to a message, an object must have a "handler" for that message in its script.
  2200. ript.
  2201. d is a line identifying the end of the handler. In the following exercise you will write a simple buttonUp handler.
  2202. Another example of the step cont
  2203. sectionNumber
  2204.     Here's another example of using the step control structure.
  2205. 1.    Edit the script of the "Clear Names" button.
  2206. 2.    Create a buttonUp handler to clear the names of the fields. The fields are called "Name1", "Name2", and so on, through "Name6".
  2207.     To see one solution, switch to Reader level and click the "Hint" button.
  2208. Another example of the step control structure
  2209. Name1
  2210. Name6
  2211. Name5
  2212. Frank
  2213. Name4
  2214. Name3
  2215. Henderson
  2216. Name2
  2217. Bertrand
  2218. Clear Names
  2219. to handle buttonUp
  2220.     step i from 1 to 6
  2221.         set fieldName to "Name" & i
  2222.         clear the text of field fieldName
  2223. endddd1 seconds
  2224. end    beep 10
  2225.     end if
  2226. -- Show 
  2227. the hint.
  2228. "Hint"
  2229. buttonUp
  2230. buttonUp
  2231. exercise
  2232. Introduction
  2233. Message Demo
  2234. Close the workbook
  2235. -- When entering the 
  2236. label on 
  2237. 8icon
  2238. /s_launchedFrom
  2239. ^. If 
  2240. Lworkbook 
  2241. -- Quick Tour, 
  2242. ewill be "
  2243. ." Otherwise, 
  2244. probably be 
  2245. "returnBook" 
  2246. enterPage
  2247. enterPage
  2248. returnBook
  2249. s_launchedFrom
  2250. Close the workbookk
  2251. After completing the exercises
  2252. in this workbook, you are
  2253. ready to begin writing
  2254. scripts and applications
  2255. on your own....
  2256. Double-click the book icon to close this workbook. If you opened the workbook from the Application Sampler, the Application Sampler will be opened............... to open another book called the OpenScript Work Book. When         you are finished 
  2257.         with the Work 
  2258.         Book the 
  2259.         Quick Tour will 
  2260.         resume.
  2261. returnBook
  2262. -- When 
  2263. }-clicked, 
  2264. -- label 
  2265. d(since 
  2266. -- become unshaded) 
  2267. message (which 
  2268. , be intercepted
  2269. handler 
  2270. a mouse 
  2271. pressed over 
  2272. Hchanging its 
  2273. -- Trap 
  2274. ignore 
  2275. }messages
  2276. Click
  2277. buttonDoubleClick
  2278. buttonDown
  2279. buttonUp
  2280. buttonDoubleClick
  2281. 0,100,0
  2282. buttonDown
  2283. 0,50,100
  2284. buttonUp
  2285. :PHYSSIZE
  2286. sectionNumber
  2287. What this Book Contains
  2288. Object Drawing and Display
  2289. Menus
  2290. Messages
  2291. Accessing Items in Lists
  2292. A simple object browser
  2293. User-defined functions, continue
  2294.  Cont.
  2295. OpenScript Online Help
  2296. Control Structures
  2297. Ask and Request
  2298. Types of objects
  2299. sectionNumber
  2300. Types of objects
  2301. ToolBook has several different types of objects:
  2302. Books                                Record fields
  2303. Backgrounds                        Hotwords
  2304. Pages                                Groups
  2305. Buttons                                Graphic objects (pictures, draw
  2306. Fields                                objects, and paint objects)
  2307.                         
  2308. Writing a simple buttonUp handle
  2309. sectionNumber
  2310. 1.    Create a rectangle on this page.
  2311.     Use the rectangle tool from the tool palette.
  2312. 2.    Edit the script of the rectangle.
  2313. Click the selection tool in the tool palette.
  2314.     Choose Graphic Properties from the Object menu and click the Script button.
  2315. 3.    Enter and save the following script (use the Exit/Update command in the Script menu):
  2316.     to handle buttonUp
  2317.             hide self
  2318.             pause 2 seconds
  2319.             show self
  2320.         end
  2321. 4.    Switch to Reader level and click the rectangle.    
  2322.     What messages did clicking the rectangle send? Which message caused the rectangle to disappear? What about the other message????????????????????????????????????????????????????????????????
  2323. Writing a simple buttonUp handler
  2324. Please note:  Read the instructions on this page carefully before executing them. 
  2325. Other windows will appear in front of this window. If you need to move these windows to read the instructions, drag their title bar.
  2326. Object identifiers
  2327. sectionNumber
  2328. startSection
  2329. Object identifiers
  2330. In writing scripts you often have to refer to an object, perhaps to hide or show it, or to change it in some way. To refer to an object you use a combination of the object's type (e.g. field, button) and the object's name or ID. If the object isn't on the current page you may also have to add location information. As an example, to refer to the blue ellipse 
  2331. on this page you could use ellipse "oval" or 
  2332. ellipse ID 0....pic".
  2333. Hiding and showing objects using
  2334. 1.    Display the Command window.
  2335.     Press Shift+F3.
  2336. 2.    Type the following commands in the Command window. Press Enter after each command.
  2337.     hide rectangle "box"
  2338.     show rectangle "box"
  2339.     hide menubar
  2340.     show menubar
  2341.     hide toolpalette
  2342.     show toolpalette
  2343.     move toolpalette to 100,100
  2344. 3.    What commands would you type to hide and show the pattern palette? The color tray?
  2345.     Hint: If you don't know, try using OpenScript Help.
  2346. manual.
  2347. Hiding and showing objects using the Command window
  2348. sectionNumber
  2349. Setting and getting field text i
  2350. 1.    Type the following commands in the Command window. Press Enter after each command:
  2351.     set text of field "thatfield" to text of field "thisfield"
  2352.     clear text of field "thisfield"
  2353.     set text of field "thisfield" to "Hi there!"
  2354.     put the third word of text of field "thatfield"
  2355.     put the last word of text of field "thisfield"
  2356.     put words 4 to 7 of text of field "thatfield"
  2357. 2.    How would you refer to the third through thirteenth characters of field thatfield???ters of field thatfield?"
  2358. 3.    How would you refer to the third through thirteenth characters of field thatfield?
  2359. Setting and getting field text in the Command windowow
  2360. thisfield
  2361. The text of a field is one of its properties just like its border style. and can be set with an OpenScript statement.
  2362. thisfield
  2363. thatfield
  2364. thatfield
  2365. sectionNumber
  2366. ToolBook programming
  2367. ToolBook programminging
  2368. In traditional programs, the program controls the user by requesting input and displaying output..
  2369. PRINT "What's your name?";
  2370. INPUT Name$
  2371. PRINT "Hi, "; Name$
  2372. PRINT "Enter a number: ";
  2373. INPUT Num
  2374. PRINT "The square root of "; Num; " is: "; SQRT(Num)
  2375. FUNCTION Fact(n)
  2376.     f = 1
  2377.     FOR i=2 to n
  2378.         f = f*i
  2379.     NEXT i
  2380.     Fact = f
  2381. END FUNCTIONNNNNNNNNNNNNNNN
  2382. What's your name? Sue
  2383. Hi, Sue
  2384. Enter a number: 4
  2385. The square root of 4 is 2
  2386. startSection
  2387. sectionNumber
  2388. The hierarchy 2
  2389. ontinued
  2390. sectionNumber
  2391. For example, if you click a page object that does not have a handler for the buttonDown message, the message continues to the page, then to the background, and so on, until it reaches the ToolBook system..m.
  2392. The hierarchy, continued....
  2393. Spark
  2394. height
  2395. height
  2396. arrow
  2397. false
  2398. false
  2399. The ToolBook difference
  2400. sectionNumber
  2401. The ToolBook differenceg
  2402. In a ToolBook application, the user controls the program. Everything the user does (like clicking a button) sends a message to an object which runs a "handler" to respond.
  2403. Try to click the objects for which a script is shown.n.
  2404. Number:
  2405. number
  2406. -- When 
  2407. clicked, 
  2408. (the user 
  2409. place 
  2410. ("What 
  2411. x"Cancel" 
  2412. buttonUp
  2413. buttonUp
  2414. What number?
  2415. Cancel
  2416. 81fdas
  2417. to handle buttonUp
  2418.     get text of self
  2419.     ask "What number?" with it
  2420.     if sysError is not "Cancel" then
  2421.         set the text of self to it
  2422. end buttonUpp
  2423. Calculate
  2424. -- When 
  2425. clicked, calculate the square root 
  2426. place results 
  2427. 3"answer" 
  2428. -- The actual 
  2429. here 
  2430. a little more complicated than
  2431. {impler 
  2432. , because 
  2433. also implement
  2434. -- error trapping.
  2435. Our testers had so much fund trying
  2436. , we 
  2437. placate them.
  2438. -- Don't suspend execution 
  2439. r            -- Clear 
  2440. P-- Reset 
  2441. default
  2442. y        -- If there was 
  2443. "Cannot take 
  2444. & n & """!"
  2445. buttonUp
  2446. buttonUp
  2447. number
  2448. answer
  2449. Cannot take the square root of "
  2450. answer
  2451. Calculate
  2452. to handle buttonUp
  2453.     get text of field "number"
  2454.     clear text of field "answer"
  2455.     if it is not null then
  2456.         get sqrt(it)
  2457.         set text of field "answer" to it
  2458. end buttonUp ndld "answer"
  2459. Answer
  2460. Square Root:is:::::
  2461. Name versus ID
  2462. sectionNumber
  2463. Name versus ID
  2464. You can refer to an object using its name, if it has one, or its ID. You can name an object using the Properties dialog box or by setting the Name property for the object. The ID is assigned by ToolBook and is unique for each object. 
  2465. It is usually best to refer to objects by name. When you cut and paste an object, its ID changes, so references to the old ID will be invalid. The name does not change unless you change it...old ID will be invalid. The name does not change unless you change it.ess you change it.
  2466. An object's location
  2467. An object's locationame
  2468. If the object you're referring to isn't on the current page you may have to add location information to refer to it. For example, to refer to a button on the background you might use the following:
  2469. button "Next Page" of background "Database"
  2470. mple shows you the namess of 
  2471. sectionNumber
  2472. Handlers in objects
  2473. sectionNumber
  2474. If the script of the object contains a handler for the buttonDown message, the object's handler is executed and the message stops..
  2475. Handlers in objectsarchy
  2476. Spark
  2477. height
  2478. height
  2479. button script
  2480. to handle buttonDown
  2481.     beep 10
  2482. to handle myMessage
  2483.     go to page "Test"
  2484. end"Test"
  2485. arrow
  2486. -- Animate the message demo 
  2487. showMe
  2488. moveLSpark "et1"
  2489. showMe
  2490. showMe
  2491. moveLSpark
  2492. button script
  2493. button script
  2494. button script
  2495. Ask and request
  2496. Ask and request Commands
  2497. The ask and request commands are useful for getting information or choices from a user. The ask command asks the user to enter some text. Whatever the user types is placed in the special variable, It.
  2498. The request command displays a message and asks the user to click a button in response. The text on the button clicked is placed in the special variable, It.
  2499. in the container, IT.
  2500. startSection
  2501. sectionNumber
  2502. Handling keystrokes
  2503. sectionNumber
  2504. startSection
  2505. Handling keystrokess
  2506. Sometimes you want to respond to a user based on characters he or she types at the keyboard. You can do this with a keyChar handler. One common use of the keyChar handler is to check data as it is typed to make sure it is valid for the field.
  2507. The following exercise shows how to write a keyChar handler to make sure data is numeric.ic.numeric.meric.ic.
  2508. Handlers in pages
  2509. sectionNumber
  2510. If the object does not have a buttonDown handler but the page does, the page's handler is executed and the message stops..................
  2511. Handlers in pagesarchy, cont.
  2512. Spark
  2513. height
  2514. height
  2515. page script
  2516. to handle buttonDown
  2517.     beep 10
  2518. to handle myMessage
  2519.     go to page "Test"
  2520. arrow
  2521. buttU
  2522. -- Animate the message demo 
  2523. showMe
  2524. moveLSpark "et1"
  2525. showMe
  2526. showMe
  2527. moveLSpark
  2528. moveLSpark
  2529. page script
  2530. page script
  2531. page script
  2532. Using the request command
  2533. 1.    Create a button and label it "Decision".
  2534.     Use the button tool from the tool palette.
  2535. 2.    Edit the button's script and type:
  2536.     to handle buttonUp
  2537.         request "Save humanity or not?" with \
  2538.             "Save" or "Destroy"
  2539.         set text of field "fate" to it
  2540.     end buttonUp
  2541. 3.    Switch to Reader level and click the button.
  2542.     Try this a couple of times, making different choices. Which choice is the default choice? Try adding a third choice, "Neither" (remember, you can look in OpenScript Help for information on the request command). What's the difference between ask and request?anual).
  2543. Using the request command
  2544. Fated: fate
  2545. sectionNumber
  2546. To get and to set handlers
  2547. User-defined properties are commonly used to store values. By defining a to get and a to set handler for an object, however, you can create a user-defined property that is much more powerful.
  2548. The following exercise shows how to define a size property for an object such that setting the object's size will cause its bounds to change..
  2549. ndle=
  2550. startSection
  2551. sectionNumber
  2552. To get and to set handlers
  2553. Creating a self-sorting field
  2554. sectionNumber
  2555.     To create a self-sorting field, write a handler in the field's script to handle a user-defined message, such as sortLines. Then, to sort the lines of the field from the Command window, type:
  2556.     send sortLines to field <fieldname>
  2557.     where <fieldname> stands for the name of the field.
  2558. 1.    Create a field.
  2559. 2.    Write a sortLines handler for the field that sorts the field's lines.
  2560.     Remember the terms my and self can be used to refer to the object containing a script. If you want to see one solution, switch to Reader level and click the "Hint" button....Hint button......l and click on the Hint button.....................
  2561. Creating a self-sorting field
  2562. -- Show 
  2563. the hint.
  2564. "Hint"
  2565. buttonUp
  2566. buttonUp
  2567. -- Handler to sort a field. The handler must be 
  2568. -- located in the field's script and is activated by 
  2569. -- sending a sortLines message to the field. This
  2570. -- handler uses a Bubble sort algorithm.
  2571. to handle sortLines
  2572.     get my text
  2573.     set N to textLineCount(it)
  2574.     clear my text
  2575.     step i from N to 2 by -1
  2576.         step k from 1 to i-1
  2577.             if textLine i of it < textLine k of it as text 
  2578.                 set temp to textLine i of it
  2579.                 set textLine i of it to textLine k of it
  2580.                 set textLine k of it to temp
  2581.             end if
  2582.         end step
  2583.     end step
  2584.     set my text to it
  2585. enddd
  2586. Working with Objects from the Co
  2587. Adding Menus and Menu Items
  2588. Creating a Self-Sorting Field
  2589. The ToolBook Difference
  2590. Types of Expressions
  2591. A user-defined function for chec
  2592. OpenScript commands
  2593. Verifying data during input with
  2594. A Self-Sorting Field
  2595. Navigation
  2596. Listing All Objects on a Page
  2597. Moving a Draw Object
  2598. Using the debugger to interrupt 
  2599. Using the debugger to interrupt
  2600. Push and pop
  2601. sectionNumber
  2602. startSection
  2603. Push and pop
  2604. Lists are a powerful feature of ToolBook. The push and pop commands allow you add items to and remove items from a list. Pushing an item places the item at the beginning of the list. Popping an item removes it from the beginning. Try clicking the two "Show" buttons for a demonstration.a demonstration.
  2605. Items
  2606. Three
  2607. Seven
  2608. Show Push
  2609. -- When 
  2610. clicked, 
  2611. the "
  2612. " arrow (
  2613. one pointing 
  2614. Ftake 
  2615. Mlist" 
  2616. . Then, 
  2617. . If there are no lines 
  2618. , display a message 
  2619. that effect.
  2620. "pushArrow"
  2621. "popArrow"
  2622. "Items" 
  2623. . Try popping 
  2624. "List"
  2625. buttonUp
  2626. buttonUp
  2627. pushArrow
  2628. popArrow
  2629. Items
  2630. No items to push. Try popping items first.
  2631. items
  2632. items
  2633. Show Push
  2634. Show Pop
  2635. -- Show the "
  2636. " arrow (
  2637. one pointing 
  2638. 2list" 
  2639. removes 
  2640. places 
  2641. ). If there are no 
  2642. , display a message 
  2643. that effect.
  2644. "pushArrow"
  2645. "popArrow"
  2646. "List" 
  2647. . Try pushing 
  2648. "Items"
  2649. buttonUp
  2650. buttonUp
  2651. pushArrow
  2652. popArrow
  2653. No items to pop. Try pushing items first.
  2654. Items
  2655. Show Pop
  2656. pushArrow
  2657. List:
  2658. Item:
  2659. popArrow
  2660. Navigating in this Book
  2661. Advanced topics
  2662. Popping items from a List
  2663. Handling Key Strokes
  2664. Expressions
  2665. Moving a draw object using the s
  2666. Handling keystrokes
  2667. Navigating in this book
  2668. Navigating in this book
  2669. On explanation pages you can 
  2670. click on the arrow buttons to turn 
  2671. pages. Click the Table of 
  2672. Contents button to return to the 
  2673. table of contents.
  2674. Text on this page explains a topic.cg a topic
  2675. Title
  2676. Explanation Page
  2677. Table of Contents
  2678. Table of Contents
  2679. 8370,5460
  2680. 7764,5464
  2681. startSection
  2682. sectionNumber
  2683. The Command window
  2684. sectionNumber
  2685. startSection
  2686. The Command windowWindow
  2687. Although OpenScript is used most often in writing scripts, it can also be used directly in the Command window to do things that would be difficult or impossible with a menu command or with a mouse.ld be difficult or impossible with a menu. following pages contain exercises using OpenScript and the Command Window...uld be difficult or impossible through a menu. The following pages contain exercises using OpenScript and the Command Window.
  2688. :PHYSSIZE
  2689. User-defined properties
  2690. sectionNumber
  2691. startSection
  2692. User-defined properties
  2693. In addition to an object's built-in properties, you can create your own properties. The following exercise shows an example of creating a user-defined property to store the original bounds of an object so the object can be restored to its original size after its size has been changed.been changed.
  2694. User-defined messages
  2695. sectionNumber
  2696. startSection
  2697. User-defined messages
  2698. Through the use of custom menus, message handlers, and the send command, you can define your own messages and handlers.
  2699. The following exercise shows a simple example of creating a user-defined message and handler. For an example of defining your own menus, see the section on menus.
  2700. Menus
  2701. ontrol
  2702. sectionNumber
  2703. startSection
  2704. Menuslllllll
  2705. You can use OpenScript to customize ToolBook's pull-down menus. You can add or remove menus and menu items as well as change the way ToolBook responds to existing menu items...o existing menu items.
  2706. Message Demo
  2707. -- When entering 
  2708. the speed 
  2709.     ark 
  2710. -- switch 
  2711. level.
  2712. 4s_mLSpeed
  2713. -- Move 
  2714. \message hierarchy animations. The
  2715. $, "What", 
  2716. Ualong which 
  2717. travels.
  2718. -- This handler assumes 
  2719. -- finished moving 
  2720. displays 
  2721. large
  2722. -- splatting spark, "Bing".
  2723. moveLSpark what
  2724. "bing" 
  2725. - height 
  2726. z" / 2
  2727. ackground
  2728. enterbackground
  2729. moveLSpark
  2730. enterbackground
  2731. reader
  2732. s_mLSpeed
  2733. moveLSpark
  2734. height
  2735. spark
  2736. height
  2737. spark
  2738. spark
  2739. spark
  2740. spark
  2741. spark
  2742. s_mLSpeed
  2743. Table of Contents
  2744. -- Return 
  2745. the Table 
  2746. Contents.
  2747. buttonUp
  2748. buttonUp
  2749. Table of Contents
  2750. Table of Contents
  2751. -- If 
  2752. moved, 
  2753. a user-defined property, home, 
  2754. -- the 
  2755. graphic covering 
  2756. -- When 
  2757. Bmouse 
  2758. pressed, 
  2759. released, 
  2760. w. Finally, 
  2761. -- Move 
  2762. -- depending on 
  2763. parameter, x, which can be 
  2764. H15,15
  2765. buttonDown
  2766. moved
  2767. buttonUp
  2768. press
  2769. moved
  2770. buttonDown
  2771. press
  2772. buttonUp
  2773. press
  2774. previous
  2775. press
  2776. 7755,5480
  2777.      
  2778. Right
  2779. -- If 
  2780. moved, 
  2781. a user-defined property, home, 
  2782. -- the 
  2783. graphic covering 
  2784. -- When 
  2785. Bmouse 
  2786. pressed, 
  2787. released, 
  2788. w. Finally, 
  2789. -- Moves 
  2790. sets 
  2791. -- depending on 
  2792. parameter, x, which can be 
  2793. H15,15
  2794. buttonDown
  2795. moved
  2796. buttonUp
  2797. press
  2798. moved
  2799. buttonDown
  2800. press
  2801. buttonUp
  2802. press
  2803. press
  2804. 8370,5475
  2805.      
  2806. ToolBook
  2807. Systemmm
  2808. Background
  2809. MouseButton
  2810. Page Leader
  2811. Title
  2812. Paths
  2813. Show Example
  2814. -- When the mouse 
  2815. pressed, turn 
  2816. -- graphics on 
  2817. 0screen 
  2818. B"mouseButton" 
  2819. "Arrow" 
  2820. released, 
  2821. showMe message 
  2822. animated demo 
  2823. 0,75.3125,0
  2824. buttonDown
  2825. buttonUp
  2826. buttonDown
  2827. mouseButton
  2828. 0,0,0
  2829. Arrow
  2830. 0,0,0
  2831. buttonUp
  2832. showMe
  2833. mouseButton
  2834. Arrow
  2835. 0,100,0
  2836. Show Example
  2837. Looping control structures
  2838. Listing objects continued
  2839. Messages
  2840. Messages
  2841. sectionNumber
  2842. startSection
  2843. Messages Messageslers, Cont.
  2844. A user's actions cause 
  2845. messages to be sent. Each 
  2846. message has a name. For 
  2847. example, clicking an object with
  2848. the mouse causes two messages 
  2849. to be sent to the object: 
  2850. buttonDown and buttonUp.
  2851. Button Message Example
  2852. -- Animate the two 
  2853. Bmessages 
  2854. example.
  2855. doMouse
  2856. B"mouseClick" 
  2857. "downMessage"
  2858.     Move 
  2859. 6435, 2647
  2860. 6390, 2557
  2861. 6300, 2467
  2862. 6210, 2332
  2863. 6120, 2212
  2864. 6045, 2122
  2865. 5910, 1942
  2866. 5745, 1852
  2867. 5565, 1687
  2868. 5430, 1597
  2869. "upMessage"
  2870. 6435, 2647
  2871. 6390, 2557
  2872. 6300, 2467
  2873. 6210, 2332
  2874. 6120, 2212
  2875. 6045, 2122
  2876. 5910, 1942
  2877. 5745, 1852
  2878. 5565, 1687
  2879. 5430, 1597
  2880. doMouse
  2881. doMouse
  2882. mouseClick
  2883. downMessage
  2884. button
  2885. mouseClick
  2886. upMessage
  2887. button
  2888. matte
  2889. button
  2890. inverse
  2891. false
  2892. arrow
  2893. mouseClick
  2894. inverse
  2895. upMessage
  2896. buttonUp
  2897. downMessage
  2898. buttonDown
  2899. Show Example
  2900. -- Send a doMouse message 
  2901. the grouped 
  2902. example," 
  2903. animate 
  2904. "Button Message Example"
  2905. buttonUp
  2906. buttonUp
  2907. FdoMouse
  2908. Button Message Example
  2909. Show Example
  2910. arning ToolBook
  2911. System
  2912. enScript Exercises
  2913. s Rmn
  2914. `D|D|
  2915. -- a 
  2916. renumbering a 
  2917. n > 0 
  2918. enterBook
  2919. renumber
  2920. enterBook
  2921. sizeToPage
  2922. renumber
  2923. :REPORTDATA
  2924. :CONDITIONDATA
  2925. Text of RecordField "Instructions" is "null" As Text
  2926. Text of RecordField "Instructions" is null
  2927. OpenScript Workbook
  2928. System
  2929. y`D|D|
  2930. `D|D|
  2931. ]D|D|
  2932. gD|D|
  2933. \D|D|
  2934. `D|D|
  2935. `D|D|
  2936. `D|D|
  2937. `D|D|
  2938. `D|D|
  2939. rminal
  2940. `D|D|
  2941. `D|D|
  2942. `D|D|
  2943. fault
  2944. 9_D|D|
  2945. pageNumber is 103 or pageNumber is 104
  2946. pageNumber is 103 or pageNumber is 104
  2947. pageNumber is 103 or pageNumber is 104
  2948. pageobjs
  2949. `D|D|
  2950. :PRINTLAYOUT
  2951. `D|D|
  2952. `D|D|
  2953. u`D|D|
  2954. 3^D|D|
  2955. \D|D|
  2956. \D|D|
  2957. \D|D|
  2958. Title
  2959. Instructions
  2960. "QuikTour"
  2961. "OSWorkBk"
  2962. "~pUnable 
  2963. Quick 
  2964. enterBook
  2965. previous
  2966. author
  2967. leaveBook
  2968. enterBook
  2969. reader
  2970. sizeToPage
  2971. s_launchedFrom
  2972. author
  2973. o MmenuPop
  2974. previous
  2975. o MmenuPop
  2976. leaveBook
  2977. QuikTour
  2978. OSWorkBk
  2979. QuikTour.v
  2980. ~pUnable to return to the Quick Tour.
  2981. launchedFrom
  2982. s_launchedFrom
  2983. exercise
  2984. Instructions
  2985. Title
  2986. To turn the page, press Ctrl+Right Arrow.............................................
  2987. -- Make sure ToolBook 
  2988. )Author level 
  2989. )the beginning
  2990. each exercise.
  2991. enterPage
  2992. enterPage
  2993. Author
  2994. author
  2995. Control structures
  2996. Control structures
  2997. OpenScript contains several control structures for both branching and looping within a script. The following pages show some examples of the branching and looping control structures. These are followed by exercises.es.
  2998. startSection
  2999. sectionNumber
  3000. User-defined messages 1
  3001. sectionNumber
  3002.     In this exercise, the button, "Send message," sends a user-defined message to the rectangle. The rectangle has a handler that responds to the message.
  3003. 1.    Type the following two commands in the Command window, pressing Enter after each command:
  3004.      set script of rectangle "rec" to text of field "script1"
  3005.      set script of button "send" to text of field "script2"
  3006.     This copies the scripts into the two objects
  3007. 2.    Switch to Reader level and click the "Send Message" button.
  3008. 3.    Create another user-defined message called "changeColor" that causes the rectangle to turn red then back to white.ar.
  3009. User-defined messagess
  3010. Send message
  3011. script1
  3012. to handle hideAndShow
  3013.         hide self
  3014.         pause 2 seconds
  3015.         show self
  3016. y fillcolor to white
  3017. end blush
  3018. script2
  3019. to handle buttonUp
  3020.         send hideAndShow to rectangle "rec"
  3021. endUpp
  3022. Script11
  3023. Script22
  3024. ect so t
  3025. Drawing objects from a script
  3026. sectionNumber
  3027.     In this exercise you will write a script to draw a rectangle.
  3028. 1.    Edit the script of the button, "Draw Square".
  3029. 2.    Look at the draw command in OpenScript Help.
  3030. 3.    Create a buttonUp handler to draw a rectangle from 6000,900 to 7500,2400.
  3031.     For a hint, switch to Reader level and click the "Hint" button.
  3032. 4.    Switch to Reader level and try the button.
  3033. 5.    Try drawing an ellipse or polygon.
  3034. Drawing objects from a script
  3035. Draw Square
  3036. Draw Square
  3037. to handle buttonUp
  3038.     draw rectangle from 6000,900 to \
  3039.         7500,2400
  3040.     set the fillcolor of the selection to blue
  3041. end buttonUpppppppppppppppp
  3042. -- Show 
  3043. the hint.
  3044. "Hint"
  3045. buttonUp
  3046. buttonUp
  3047. A simple object browser using ri
  3048. sectionNumber
  3049.     In this exercise you will write a handler that displays information on an object when it is clicked with the right mouse button. To prepare, look at the rightButtonClick message and the objectFromPoint function in OpenScript Help.
  3050. 1.    Write a handler for the page that uses the request command to display an object's ID, name and parent when the object is clicked with the right mouse button. 
  3051.     For a hint, switch to Reader level and click the "Hint" button. 
  3052. 2.    Test your script by switching to Reader level and clicking objects on the page with the right mouse button.
  3053.     Why doesn't clicking background objects work? Try modifying the handler to edit the script of an object when it is clicked with right mouse button.ked with right mouse button.ht mouse button. mouse button..button.
  3054. A simple object browser using rightButtonClick
  3055. blank hint
  3056. to handle rightButtonUp loc, isShift, isCtrl
  3057.     get objectFromPoint(loc)
  3058.     if it is not null
  3059.         clear objInfo
  3060.         put "Object:" & TAB & it & CRLF after objInfo
  3061.         put "Name:" & TAB & name of it & CRLF \
  3062.             after objInfo
  3063.         put "Parent:" & TAB & parent of it & CRLF \
  3064.             after objInfo
  3065.         request objInfo
  3066. end rightButtonUpppppppppppppppppppppppt onto x
  3067.         end
  3068. end buttonUpp
  3069. -- Show 
  3070. the hint.
  3071. "Hint"
  3072. buttonUp
  3073. buttonUp
  3074. Red Ellipse
  3075. Slice of Blueberry
  3076. Click Me
  3077. -- Move the 
  3078. B50 steps 
  3079. S. Each
  3080. units (1/1440 
  3081. inch). When finished, 
  3082. -starting 
  3083. which was saved 
  3084. -- "home" user-defined property.
  3085. H-30, 0
  3086. buttonUp
  3087. buttonUp
  3088. Click Me
  3089. Square
  3090. Moving a draw object
  3091. sectionNumber
  3092.     In this exercise you will write a script to move 
  3093.     the red dot around the screen.
  3094. 1.    Edit the script of the button "Fun With Dot" and create a buttonUp handler to move the dot to the following points:
  3095.     8000, 100
  3096.     8000, 4000
  3097.     6300, 2050
  3098.     4600, 4000
  3099.     4600, 100
  3100.     Use any order you want. For one solution, switch to Reader level and click the "Hint" button.......
  3101. Moving a draw object
  3102. funbutton
  3103. Fun With Dot
  3104.  to handle buttonUp
  3105.          move ellipse "dot" to 8000,100
  3106.         move ellipse "dot" to 8000,4000
  3107.         move ellipse "dot" to 6300, 2050
  3108.         move ellipse "dot" to 4600,4000
  3109.         move ellipse "dot" to 4600,100
  3110. end buttonUppttonUppppppppppppnUp
  3111. -- Show 
  3112. the hint.
  3113. "Hint"
  3114. buttonUp
  3115. buttonUp
  3116. Changing an object's color prope
  3117. sectionNumber
  3118.     In this exercise there are three ellipses: "scoop", on top of the cone; "Vanilla", on top of the vanilla tub and "Chocolate", on top of the chocolate tub. The script displayed in the white field shows how the color of the scoop ellipse (its fillColor property) can be set to the fillColor of "Chocolate" or "Vanilla".
  3119. 1.    Look at the script. Which lines change the fillColor property of the ellipse, "scoop"?
  3120.     This is the script of the button labeled "Chocolate or Vanilla?"
  3121. 2.    Switch to Reader level and click the button.
  3122.     Try again with the other flavor...the other flavor..r..avor..n the button.
  3123.     Try it again with the other flavor..hen switch back to Author level.
  3124. Changing an object's color properties
  3125. scoop
  3126. vanilla
  3127. chocolate
  3128. Flavor
  3129. -- Use the 
  3130. a choice 
  3131. flavor 
  3132. -- user, 
  3133. ."scoop" 
  3134. accordingly.
  3135. "What 
  3136. @would you like?" 
  3137.     "Chocolate" 
  3138. "Vanilla"
  3139. buttonUp
  3140. buttonUp
  3141. What flavor would you like?
  3142. Chocolate
  3143. Vanilla
  3144. Chocolate
  3145. scoop
  3146. Chocolate
  3147. scoop
  3148. Vanilla
  3149. Chocolate or Vanilla?
  3150. Script1
  3151. to handle buttonUp
  3152.     request "What flavor would you like?" with \
  3153.     "Chocolate" or "Vanilla"
  3154.     if It is Chocolate
  3155.         set the fillcolor of ellipse "scoop" to the \
  3156.         fillcolor of ellipse "Chocolate"
  3157.     else
  3158.         set the fillcolor of ellipse "scoop" to the \
  3159.         fillcolor of ellipse "Vanilla"
  3160.     end if
  3161. end buttonUpttonUptonUpttonUptonUpttonUppppppp
  3162. Moving a draw object using the s
  3163. sectionNumber
  3164.     The step control structure can be used for animation. In this exercise it is used for moving the red dot around the screen.
  3165. 1.    Edit the script of the button, "Fun with Dot".
  3166. 2.    Create a buttonUp handler to move the dot to the bottom of the screen and back.
  3167.     The starting position is 7750, 100 and the ending position is 7750, 5000. One way to write this handler is to use the step control structure and the move command. For information on these, see OpenScript Help. To see one solution, switch to Reader level and click the "Hint" button.
  3168. 3.    How could you move the dot in a square around the screen?en? screen??
  3169. Moving a draw object using the step control structure
  3170. to handle buttonUp
  3171.     move ellipse "dot" to 7750, 100
  3172.     step yPos from 100 to 5000 by 100
  3173.         move ellipse "dot" to 7750, yPos
  3174.     end step
  3175.     step yPos from 5000 to 100 by -100
  3176.         move ellipse "dot" to 7750, yPos
  3177.     end step
  3178. end buttonUp 0,var2
  3179.         end step
  3180.         step var3 from 300 to 1 by -10
  3181.               move ellipse "dot" by var3,0
  3182.         end step
  3183. end buttonUpW
  3184. -- Show 
  3185. the hint.
  3186. "Hint"
  3187. buttonUp
  3188. buttonUp
  3189. Fun with Dot
  3190. A buttonUp handler higher in the
  3191.     One way to handle clicking an object is to
  3192.     place a handler in the object's script. With 
  3193.     lots of similar objects, this can mean lots 
  3194.     of similar handlers. Using the target property, you can write a single handler on the page that handles clicking all of the similar page objects.
  3195. 1.    Edit the page script and enter the script you see to the right.
  3196. 2.    Switch to Reader level and click one of the states in the map.
  3197.     The buttonDown message is first sent to the state you click, a draw object. The object is recorded in the target property. The message is passed on to the group ("map"), then to the page. The page has a handler for the message that puts the name of the target (the state you clicked) into the "State Name" field.    
  3198. sectionNumber
  3199. A buttonUp handler higher in the hierarchyyy
  3200. State Name
  3201. Washington
  3202. Montana
  3203. Oregon
  3204. California
  3205. Nevada
  3206. Idaho
  3207. Wyoming
  3208. Arizona
  3209. New Mexico
  3210. Colorado
  3211. Texas
  3212. Oklahoma
  3213. Kansas
  3214. Nebraska
  3215. South Dakota
  3216. North Dakota
  3217. Minnesota
  3218. Missouri
  3219. Arkansas
  3220. Louisiana
  3221. Wisconsin
  3222. Illinois
  3223. Kentucky
  3224. Indiana
  3225. Tennessee
  3226. Mississippi
  3227. Alabama
  3228. Georgia
  3229. Florida
  3230. North Carolina
  3231. South Carolina
  3232. Michigan
  3233. Pennsylvania
  3234. West Virginia
  3235. Virginia
  3236. Maryland
  3237. Delaware
  3238. New York
  3239. New Jersey
  3240. Vermont
  3241. New Hampshire
  3242. Maine
  3243. Massachusetts
  3244. Connecticut
  3245. Rhode Island
  3246. Alaska
  3247. Hawaii
  3248. Hawaii
  3249. Hawaii
  3250. Hawaii
  3251. Hawaii
  3252. script1
  3253. to handle buttonDown
  3254.         set text of field "State Name" to name of target
  3255. end buttonDown
  3256. to handle buttonUp
  3257.         set the text of field "State Name" to null
  3258. end buttonUpppppppppp
  3259. A user-defined function for sort
  3260. sectionNumber
  3261.     Although lists are a powerful feature in ToolBook, there are no built-in functions for sorting lists. In this exercise, you will write a function to sort a list of text items. The following is one method for sorting a list:
  3262.     While the original list still has items in it,
  3263.         Find the largest item in the list
  3264.         Push that item onto the sorted list
  3265.         Clear that item from the original list
  3266. 1.    Edit the script of this page and write a handler that sorts a list. Call the function "sortList" and give it one parameter, the list to be sorted.
  3267.     Click the "Hint" button for one solution.
  3268. 2.    Test the function by clicking the "Sort Test" button.
  3269.     " button.
  3270.     e options menu when the debugger is displayed.......
  3271. A user-defined function for sorting a listto a dateage
  3272. to get sortList list
  3273.     clear sortedList
  3274.     while list is not null
  3275.         set biggest to 1
  3276.         step i from 2 to itemCount(List)
  3277.             get item i of list
  3278.             if it > item biggest of list as text
  3279.                 set biggest to i
  3280.             end
  3281.         end
  3282.         push item biggest of list onto sortedList
  3283.         clear item biggest of list
  3284.     return sortedList
  3285. Sort Test
  3286. ("Type the list you want 
  3287.         "z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c,b,a"
  3288. "The sorted 
  3289. :" & CRLF & sortList(
  3290. buttonUp
  3291. buttonUp
  3292. Type the list you want to sort:
  3293. z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c,b,a
  3294. The sorted list is:
  3295. sortList
  3296. Sort Test
  3297. -- Show 
  3298. the hint.
  3299. "Hint"
  3300. buttonUp
  3301. buttonUp
  3302.     used
  3303. FxZoom fxDissolve and fxWipe
  3304. -- When a sample 
  3305. clicked, install the 
  3306. "Effect" 
  3307. c"Script" 
  3308. buttonUp
  3309. buttonUp
  3310. field
  3311. Script
  3312. 180,50,100
  3313. Effect
  3314. 0,100,0
  3315. sectionNumber
  3316.     This exercise shows the effect of the different "fx" commands when changing pages. There are three scripts. Clicking on each one at Reader level will install it in the "Effect" button.
  3317. 1.    Switch to Reader level.
  3318.     Most messages aren't sent at Author level.
  3319. 2.    Click one of the scripts.
  3320.     This puts the script in the "Effect" button.
  3321. 3.    Click the "Effect" button.
  3322. 4.    Try it with the other scripts.
  3323. 5.    Make up an effect script of your own.
  3324. ript2, switch to Reader level and click the button.
  3325. 5.    Switch back to Author level and use the Command window to set the script of the button to the text of samplescript3, then switch to Reader level and click the button.
  3326. FxZoom, fxDissolve and fxWipe
  3327. Landscape
  3328. Effect
  3329. Effect
  3330. script3
  3331. to handle buttonUp
  3332.     fxDissolve slow to next page
  3333. end buttonUputtonUp#
  3334. script2
  3335. to handle buttonUp
  3336.     fxZoom to next page at sysmouseposition
  3337. end buttonUpppppppppp
  3338. script1
  3339. to handle buttonUp
  3340.     fxWipe left to gray
  3341.     fxWipe right to next page
  3342. end buttonUpd buttonUpd buttonUp
  3343. buttonUp
  3344. buttonUp
  3345. fx destination
  3346. -- When entering the 
  3347. , switch 
  3348. Reader level.
  3349. enterPage
  3350. enterPage
  3351. Reader
  3352. sectionNumber
  3353.     You made it!
  3354.     Click the "Go Back" button to return to the previous page.
  3355.     ! 4    
  3356. -- Go 
  3357. buttonUp
  3358. buttonUp
  3359. Go Back
  3360. "used
  3361. "true
  3362. OWORKBK.ico
  3363. DDDDD
  3364. DDDDDDDDD
  3365.  )4fw
  3366.