[General] Storing Values when a Morph is Persisted, How To

Philip Weaver philmaker at gmail.com
Thu Mar 5 02:34:51 CET 2009


I refocused on your other response about persisting common values but not
common objects. Until I discover how to persist one of my own Object
subclasses, I'm just sort of unpackaging and repackaging my complex objects
on the morph for now and I have that working. I'm probably making things too
difficult by not using models and the Widget class but I'll revisit those
soon. Everything will get easier when I embrace coding directly inside a
World - I keep going back and forth between my local editor and the wiki.

On Wed, Mar 4, 2009 at 1:46 AM, Robert Krahn <
robert.krahn at student.hpi.uni-potsdam.de> wrote:

> Hi Phil,
> the getTrait and setTrait methods are used by shapes, not morphs. All
> instance variables of morphs are persistent a priori. I modified your test
> code a bit:
>
> Morph.subclass("MyPersistedMorph", {
> 	
> 	handlesMouseDown : Functions.True,
> 	
> 	initialize : function($super) {
> 		
> 		console.log('PersistedMorph.initialize');
> 		$super(new lively.scene.Rectangle(new Rectangle(100, 100, 200, 200)));
> 		
> 		this.setFill(Color.green);
> 		console.log('PersistedMorph.initialize weight: ' + this.weight); // will always be undefined because
>
> 									// initialize isn't called for deserialization
>
> 	},
> 	
>
> 	onDeserialize: function() {
>
> 		console.log('PersistedMorph.onDeserialize weight: ' + this.weight); // This works
>
> 	},
> 	onMouseDown : function($super, event) {
> 		
> 		console.log('PersistedMorph.onMouseDown');
> 		console.log('PersistedMorph.onMouseDown weight: ' + this.weight);
> 		this.weight = 100;
> 		
> 		return true;
> 	}
> });
>
>
>
> Robert
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090304/1eac8386/attachment.html 




More information about the lively-kernel mailing list