[Newbie Q]Morphic /SmallTalk

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Thu Mar 16 11:49:16 UTC 2000


On Wed, 15 Mar 2000, Karl Ramberg wrote:

> I'm just starting to learn stuff here and tried to make some
> simple apps but suddenly found myself in trouble.
> I'm making two morphs and want one to act as a button and
> the other to for instance move when I click on the button.
> I did this in the etoy/ scripting and it was really easy, but
> now I can't find any way to send the message from class to class.

To move a morph, send "position: somePoint" to it. 
To make a morph respond to mouse clicks, set an eventhandler.

For example:

| a b |
a _ Morph new color: Color red; openInWorld.
b _ Morph new color: Color green; openInWorld.
a on: #mouseDown send: #value to: [b position: b position + (10 at 0)]

If you click the red morph, the green one will move to the right. It does
so by sending #value to the given block (stuff inside brackets), which
causes the code in the block to be executed.

If you were going to write a method you would set up an eventhandler that
sends a message to the button morph itself, like
	self on: #mouseDown send: #moveOtherMorph to: self
in the moveOtherMorph method you would send position: to the other morph.

HTH,

  -Bert-






More information about the Squeak-dev mailing list