Morphs differ based on how brought to life?

Dan Shafer dshafer at yahoo.com
Sun Mar 25 06:03:54 UTC 2001


Thanks to Randal and Bijan, I got it. I don't understand it 100% but at least I
got it.

In the #makeControls method of ScorePlayerMorph, the target of button actions
was being changed from self to the instance of ScorePlayer associated with this
instance of the SPM. When I coded my Close button, I did this:

r addMorphBack: (b fullCopy label: 'Close'; actionSelector: #delete).

This was just a copy-paste-edit of other lines in the method that clearly work
correctly. Bijan said I had to make sure the target of my method was set to
self, so I changed it to read:

r addMorphBack: (b fullCopy label: 'Close'; actionSelector: #delete; target:
self).

Inspecting that, I found self still referring to the SP rather than the SPM. So
I went carefully through the code for the method and I noticed it didn't change
the target inline as I had. Rather when it wanted to change the target, it
added a separate line to do so. So I changed the code to read like this:

b target: self.
r addMorphBack: (b fullCopy label: 'Close'; actionSelector: #delete).

And now it works correctly.

I'm still completely confused as to _why_ "self" in an instance method in SPM
should refer to the instance of SP associated with the morph (which just seems
wrong-headed to me). Best I can postulate is that perhaps it's related to the
notion of the model somehow, but I thought we threw out MVC when we installed
Morphic.

Anyway, it works and this will make a good beginner article which I'll now
write up and contribute back to the community so that everyone doesn't have to
go through this whole rigamarole again.

Hey, Mark Guzdial! Was this a trick question or did I just make it too hard?
(I'm famous for that in classrooms, fortunately not in books.)

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/





More information about the Squeak-dev mailing list