Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How do I find a morph by name?
Last updated at 8:24 pm UTC on 14 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.