[Newbies] Re: How to add a gif or an image to a Morph

Bert Freudenberg bert at freudenbergs.de
Thu Mar 18 13:54:39 UTC 2010

On 18.03.2010, at 14:30, K. K. Subramaniam wrote:
> On Thursday 18 March 2010 04:56:13 pm FrankBz wrote:
>> The problem is that I'm writing a a morph that should change background
>> image accordingly to user action.. 
> What exactly are you trying to do? Create a button? Create a scenic animated 
> background? Do you need to scale/rotate your background image before display?
> See ThreePhaseButtonMorph for a morph which changes its background depending 
> on mouse gestures.

Right. Also see the class side of ThreePhaseButtonMorph to see how it gets its images, e.g. in #checkBox.

You can use the same mechanism. Once you imported the image, store the form in the ScriptingSystem's formDictionary. Just open an inspector on the image morph and call

	ScriptingSystem saveForm: aForm atKey: 'myImageName'.

Later you can retrieve that form by

	ScriptingSystem formAtKey: 'myImageName'.

It would be more usual to implement this "resources dictionary" in your own class. That is, just have a class variable with a dictionary to hold the forms. Or, if there are very few forms, simply have a class variable for each (like class Cursor does).

- Bert -

More information about the Beginners mailing list