FAQ: How do I access a Morph from a Workspace?
Last updated at 2:51 pm UTC on 16 January 2006
From the mailing list:
Once you drag a widget out and place it somewhere, is there a way to assign it to a variable so that you can then send it messages? I realize you can create things with openInWorld, and that you can do a lot of things via halos and menus, but I also want to be able to send messages via a line of code to things already dragged out.
You can do this easily in a workspace.
From its window menu, check "create textual references for dropped morphs". Then drop a Morph on the Workspace. It will slide back to where it was, leaving its name (bound to the Morph in the Workspace's private dictionary).
From there you can write code in the Workspace to use it.
There is also the clipboard; you can copy a Morph to the clipboard and refer to it as
Or you can do something like (if you know there's only one of your kind of Morph about):
MyMorphClass allInstances first
Another option is to open an inspector on the morph by the debug menu and work in the evaluation pane of the inspector.
If a Morph is created by Smalltalk code, then you might give it a name.
(RectangleMorph new name: 'r3') openInWorld
Later you may access it and set for example an attribute
(World submorphNamed: 'r3') color: Color red.
Remark: The #submorphNamed: message works only for direct submorphs of World.
Question: is there a general way to find a morph by name? I tried out something like
|mymorph| World allMorphsDo: [:m| m knownName = 'Yabba' ifTrue: [ mymorph _ m ]]
But this seems awfully complicated for such a basic thing.
Morphs understand the message 'subMorphNamed:' so for the above you could do
myMorph _ World subMorphNamed: 'Yabba',