Morphs differ based on how brought to life?

Dan Shafer dshafer at yahoo.com
Sun Mar 25 07:11:48 UTC 2001


OK, Jim. Here's the entire makeControls method of the class ScorePlayerMorph.
The reason I drew the conclusion that it was a ScorePlayer and not a
ScorePlayerMorph that was getting in the loop (or path) somehow was that when I
got the walkback, it said ScorePlayer didn't understand the message
closePlayer.

I have removed #closePlayer from the class definition and am now just calling
self delete.

------ Here's the code, which works but is not completely clear to me---------

makeControls

	| b r reverbSwitch repeatSwitch |
	b _ SimpleButtonMorph new
		target: self;
		borderColor: #raised;
		borderWidth: 2;
		color: color.
	r _ AlignmentMorph newRow.
	r color: b color; borderWidth: 0; inset: 0.
	r hResizing: #shrinkWrap; vResizing: #shrinkWrap; extent: 5 at 5.
	r addMorphBack: (b fullCopy label: '<>'; actWhen: #buttonDown;
														actionSelector: #invokeMenu).
	r addMorphBack: (b fullCopy label: 'Piano Roll';		actionSelector:
#makePianoRoll).
	r addMorphBack: (b fullCopy label: 'Rewind';		actionSelector: #rewind).
	b target: scorePlayer.
	r addMorphBack: (b fullCopy label: 'Play';			actionSelector: #resumePlaying).
	r addMorphBack: (b fullCopy label: 'Pause';			actionSelector: #pause).
	reverbSwitch _ SimpleSwitchMorph new
		offColor: color;
		onColor: (Color r: 1.0 g: 0.6 b: 0.6);
		borderWidth: 2;
		label: 'Reverb Disable';
		actionSelector: #disableReverb:;
		target: scorePlayer;
		setSwitchState: SoundPlayer isReverbOn not.
	r addMorphBack: reverbSwitch.
	scorePlayer ifNotNil:
		[repeatSwitch _ SimpleSwitchMorph new
			offColor: color;
			onColor: (Color r: 1.0 g: 0.6 b: 0.6);
			borderWidth: 2;
			label: 'Repeat';
			actionSelector: #repeat:;
			target: scorePlayer;
			setSwitchState: scorePlayer repeat.
		r addMorphBack: repeatSwitch].
  "The next two lines are the only ones I changed in the method."
		b target: self.
		r addMorphBack: (b fullCopy label: 'Close'; actionSelector: #delete).
  "I realize the next line is probably no longer needed but I didn't want to
futz with it."
	b target: self.
	^ r


--- Jim Benson <jb at speed.net> wrote:
> Dan,
> 
> You should note that your code is probably still incorrect, as it changed
> the target of a previously existing button (which was aimed at a
> scorePlayer) before make a copy of it for the 'Close' button.
> 
> At this point, I would suggest that you post the entire non working method
> that you have changed, so we can take a gander.
> 
> Jim
> 
> >
> > 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/
> >
> >
> 


__________________________________________________
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