Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Recipe: How to use an IconicButton in Morphic
Last updated at 10:54 pm UTC on 12 December 2011
[Is this article relevant to learning Squeak as it exists in 2006? I get an undefined object within the first three lines of code. Can it be updated so that someone not familiar with Squeak–like me–can perform the lesson?] - see Squeak 4.2 section below.

Problem
You would like to have an icon in your Morphic world which activates the evaluation of a block of code when clicked.

Solution
You might want to use an IconicButton. If the action you want to perform is relatively simple, you don't even have to override anything.

target := [self doSomething].
i _ IconicButton new.
i labelGraphic: aForm.
i target: target.
i actionSelector: #value.
i openInWorld.


The "target" in the above will be evaluated when you click on the button. You can pass any number of arguments to the target as well.

Source: Mailing list - ohshima@is.titech.ac.jp / Fri, 26 Nov 1999

See also IconicButton



For Squeak 4.2 this works if you open a Transcript window then type the following into a workspace:

target := [Transcript show: 'Button Pressed!'; cr].
i := IconicButton new.
i target: target.
i actionSelector: #value.
i openInWorld.


Then select the above text, (Cmd D) DoIt and you'll get a new button. Press the button and the Transcript should print the message.