The Open Source Physics website will be unavailable Friday evening through Saturday afternoon as electrical work occurs in the American Center of Physics server room. Down time will begin at 6PM Eastern Time on Friday. Service is expected to resume by 6PM on Saturday, July 30.

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Question about dragable and interactive Objects post and replies

Return to the Question about dragable and interactive Objects thread
Login to post to this thread

Interactive 2D shapes question - Nov 6, 2011 at 1:25AM
Eduardo Garcia
13 Posts

Hello again:

I am trying to do some interactive 2D shapes, like buttons that change color for example, in EJS.

I am having a problem with making them "clickable". If I choose the 2DShape to not be dragable, the object I make cannot be made clickable, so I can't execute functions when the user clicks on it.

The only way I have found to make them clickable is to make them dragable in either direction. If I choose "Dragable: ENABLED_NONE" they become not clickable.

Is there a way to make them clickable but not dragable?

Thank you for your time and patience.

Replies to Interactive 2D shapes question

Re: Interactive 2D shapes question - Nov 07 2011 1:24PM
Francisco Esquembre
207 Posts

Hum! (That's my favorite expression when someone asks for something I had not foreseen :-) )

Yes. ENABLED_NONE makes the object not insensitive to clicks.

If you enable it, you risk the user will move it in the X direction, in the Y direction, or both.

No other possibility, I am afraid. At least not yet. I would need to implement this if we find this is a good idea.

There is a workaround, though. Set the "Draggable" property to ENABLED_X. And if xPos[] is the array of the positions of the elements of the set and if you click on a given index, force the value of xPos[index] in the "On drag"action. This has the effect of repositioning the element in case the user moved it.

It's not very clean, but it should work.

If you insist, I can implement a new "Draggable" option, one that makes it responsive (i.e. clickable) but will not let the user move it at all.


Re: Re: Interactive 2D shapes question - Nov 12 2011 7:45PM
Eduardo Garcia
13 Posts


Thank you for your response, your solution works nicely!

Re: Interactive 2D shapes question - Jan 07 2012 12:43PM
Geraggelos Thanasis
1 Posts

I think there is a simpler way.
You can define a variable lets say (v)  which is the X or Y position of another object
Now if you define the clickable object position X or Y indirect, lets say (v+10)
it is clickable and not dragable. That is what I use in my models.

Geraggelos Thanasis

Post edited January 7, 2012 at 12:46 PM EST.

Re: Re: Interactive 2D shapes question - Jan 13 2012 12:54PM
Francisco Esquembre
207 Posts

Brilliant, Geraggelos!

Actually, you could use the variable of its own position (say x) and set the property to x+0.


PS: No, I didn't design it like this on purpose! :-)

Post edited January 13, 2012 at 12:50 PM EST.

The OSP Network:
Open Source Physics - Tracker - EJS Modeling
Physlet Physics
Physlet Quantum Physics