How do I sense what morph the mouse is on?

How do I sense what morph the mouse is on? like, if the mouse is on a block, on the stage, the green flag, stop button, editing area, and so on.

return this.world().hand.mouseOverList[0].constructor.name returns the name of the morph. Removing constructor.name and adding .fullCopy() returns the morph itself, but be careful as this can randomly crash Snap sometimes. Also for blocks you need to add an if statement
if (mouseover instanceof BlockMorph) return new Context(null, mouseover);

wow, thanks. Also, I can't actually get the if statement to work. can you tell me how to run it? I also don't know what to do with the .fullCopy().

(The if statement is implying that mouseover is a variable with the morph.)
var mouseover = this.world().hand.mouseOverList[0];
if (mouseover instanceof BlockMorph){
return new Context(null, mouseover.fullCopy());
} else {
return mouseover.fullCopy();
}
.fullCopy() is put after a morph to ensure that the output is a copy of it and not the actual morph. If you make it the actual morph, it will do weird things like erase blocks from the script area.

Ooooohhhhh. Thanks.

lol
image

does anyone know how to export a morph as an image? This would help a lot.

image

I get

um, I clicked result pic on the call block, but there's no call block in the image... that's weird.

You put a period between "new" and "blob."

oh... that's confusing.

I can export a new morph, but I can't figure out how to export an existing morph, like a morph that is under the mouse pointer, or from a variable.

Replace new Morph() with whatever code you use to get the morph you want.
For the morph the mouse is on replace the first line with
var morph = this.world().hand.mouseOverList[0];
For a JavaScript variable, just remove the first line and replace all instances of the variable morph with that variable's name, and move the word 'var' to the second line:
var img = yourMorphVariableHere.fullImage().toDataURL(), etc etc...
Also, I figured out a better way to do it and that one of the lines of my code was useless. This new code is easier to type and also allows for naming the files:
image

thanks so much. That is hopefully my last question.

When my mouse is over a block label it says:
"TypeError
Cannot read propety 'alpha' of null"
when I use:

Can you fix it?

sometimes it throws that error, but most of the time it just crashes snap, at least for me.

This probably still has a lot of holes in it, because there are so many different morphs and rules, but I think this fixes your problem about the labels:
var ms = this.world().hand.mouseOverList[0];
if (ms instanceof ArgMorph || ms instanceof BlockLabelMorph
|| eval(ms.constructor.name + '.uber') instanceof StringMorph
|| ms instanceof ArgMorph){
return new Context(null, ms.parent.fullCopy());
} else if (ms instanceof BlockMorph){
return new Context(null, ms.fullCopy());
} else if (ms instanceof InputSlotStringMorph){
return new Context(null, ms.parent.parent.fullCopy());
} else {
return ms.fullCopy();
}

yeah that only happens when you click the block directly for some reason, dont do that

I've been pressing space to select the morph, like, when I press the space bar, it selects the morph at the mouse.

It never crashed for me when using spacebar, but it does when clicking the block
(with updated code)