How do I find a morph by name?
Last updated at 12:39 pm UTC on 18 December 2017
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.
Answer
Morphs understand the message 'subMorphNamed:' so for the above you could do
myMorph := World subMorphNamed: 'Yabba'.
Note: #subMorphNamed: only checks direct submorphs. For a component in a composite submorph use
#allMorphsDo: aBlock
or a similar method.
See also
aMorph knownName