Morphs differ based on how brought to life?

Bijan Parsia bparsia at email.unc.edu
Sun Mar 25 05:24:20 UTC 2001


On Sat, 24 Mar 2001, Dan Shafer wrote:
[snip]
> Figuring out how to make that button actually close the ScorePlayerMorph?
> That's a mouse of a different color. I must have spent four or five hours
> before I finally figured out that Morphs delete themselves by sending a message
> to their owners/parents, rather than handling the action themselves.

I don't understand what you mean. Make a ScorePlayerMorph (however you
like). Open it's menu and select "inspect morph" from the debug
submenu. In the code pane of the inspector do "self delete".

Pwfit! It's gone!

(If you do "self openInWorld", it'll come back :))

Also, if you browse the entire protocol of ScorePlayerMorph, you'll see it
inherits #delete from morph...absolutely no need to "super" and absolutely
no need to wrap the delete in somethign else.... *unless* you want to do
more clean up than mere deleting. (Or *different* clean up when closing
than mere deleting).

> So I now
> have things working so that if in a Transcript I type:
> 
> sp _ ScorePlayerMorph new.
> sp initialize.
> sp openInWorld.
> 
> and doIt I get a ScorePlayerMorph instance with a Close button. If I then send
> that little doodad a message closePlayer, which I've defined as an instance
> method in ScorePlayerMorph, it dutifully goes away.

Try, sp delete at the end of that. I bet it goes away.

> I declare success. Then I create a new ScorePlayerMorph from the New Morph...
> menu, click the Close button. Error. ScorePlayerMorph doesn't understand
> closePlayer!?

It sounds like Ned may be right about the target being the class.

> So I go back to my Transcript, create another new
> ScorePlayerMorph,, click the Close button....same result. Error.
> 
> (BTW, I'm  in Morphic here, at least I'm in a Morphic project.)
> 
> Now the closePlayer method is plainly as day right there in the
> ScorePlayerMorph, defined as follows:
> 
> closePlayer
> 
>     super delete.

The shoudl have the same effect as "self delete".

> But why does it run correctly from the Transcript (or at least appear to) but
> not from the button?

Target? In the Workspace, you *have* the object accessible.

> For completeness, here's the line I've added to the makeControls instance
> method of ScorePlayerMorph that adds the Close button:
> 
> 	r addMorphBack: (bb label: 'Close';		
>	actionSelector: #closePlayer).

If you look at the #makeControls method, you'll see things like:

		b _ SimpleButtonMorph new target: self;
				 borderColor: #raised;
				 borderWidth: 2;
				 color: color.
Make sure you get the target: self in there.

Cheers,
Bijan Parsia.





More information about the Squeak-dev mailing list