referencing objects (newbie)

Joe Koberg joe at osoft.us
Fri Feb 17 18:34:23 UTC 2006


Eddie Hillenbrand wrote:
> Hi everyone,
>
> I just downloaded Squeak two days ago, so far I love it.  I want to
> use it to teach my little sister how to program.  But first I need
> some help figuring out the basics.
>
> How do I refer to objects I create?
>
> If I create, for example, an EllipseMorph how can I refer to it in a
> Workspace, so I can send it messages using "do it"?  I've figured out
> how to open a Viewer and change the object's name, but if I try to
> send it a message in a Workspace I get an "Unknown variable" error.
>
>   

You can create the EllipseMorph from the workspace and then you
have a reference to it:

       e := EllipseMorph new openInWorld. <Alt-D>
       e<Alt-P> an EllipseMorph(1873)

Then the variable "e" refers to the new ellipse.

The World morph is the "root" of all the morphs you see on the screen.
You can ask it for one of its children by name (the name you entered in
the viewer):

      e := World submorphNamed: 'BigEllipse'. <Alt-D>
      e<Alt-P> an EllipseMorph(1873)

(<Alt-P> of course means to press Alt-P to Print It)

You can also ask any class for all of its instances, which will return
a collection of them:

      EllipseMorph allInstances

However on my squeak this returns 83 separate EllipseMorphs,
probably not what you're looking for.




Joe Koberg
joe at osoft.us





More information about the Squeak-dev mailing list