[General] Attaching Events Handlers to Morphs is Not Obvious
Robert Krahn
robert.krahn at student.hpi.uni-potsdam.de
Tue Feb 24 09:58:34 CET 2009
> How do I attach a mouse handler to a morph?
Open an inspector on a morph then, to attach a new submorph on every
click e.g., type something like this:
// make sure the Morph really wants the event
this.handlesMouseDown = Functions.True;
// overwrite my onMouseDown method
this.onMouseDown = function (evt) {
var localPoint = this.localize(evt.mousePoint);
var new Morph = Morph.makeRectangle(localPoint.extent(pt(10,10)));
this.addMorph(); // because we manually define a method
}.bind(this);
Other Mouse handler methods: onMouseMove, onMouseUp
> Most of the time I have no idea what can be edited in the inspector:
> for instance how would I edit [object Object]?.
Multiple possibilities, assume x is an object
- If you have an instance of a class and want to know its methods
x.constructor.functionNames() // constructor is the klass
- If you have an object (instance or normal JS object) try
Object.keys(x);
Object.values(x);
for (var name in x) { console.log(name + ': ' + x[name]) }
- If you want to look at the source code open the SystemBrowser
In Core.js e.g. the fundamental parts of Morphic are defined.
You can also hit loadAll. Then enter in a TextMorph 'onMouseDown',
select it and hit alt+w. You will get a list of all occurrences of
onMouseDown in the source code.
Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090224/37987242/attachment-0001.html
More information about the lively-kernel
mailing list