JavaScript exists() with object definition rather than object name

amvukovic shared this question 3 years ago

By default, the JS function exists() is used with object name, but I wonder how to use it with object definition..?

I have points A_1 to A_20 in applet and AddListener function that executes whenever a new segment is added to construction... User "draws" a segment between given points... So, let's say I want to check if a Segment(A_3,A_4) is drawn so I need to use exists() function rather than isDefined() to check this and I honestly don't know how...

I can't use isDefined() function because there are points A_3 and A_4 in construction and automatically the Segment(A_3,A_4) is defined... But, with exists() function I'm supposed to write a name of the segment which I can't because I don't know the name of a dynamically "drawn" segment...

So, I want to check if the drawn segment is a "right" one and I don't know how to use an object definition ("Segment(A_3,A_4)") with exists() function rather than object name... I also can't use getObjectName(int i) function because the segment I want to check on may still not be drawn...

Comments (3)


It's need more then one command. See global-JS in the attachment.

If create new points is not permitted with the segment-tool then additionally JS-code is needed.

(Note: setOnTheFlyPointCreationActive(false) seems not to works.

sorry one error more: attachment follows at soon as possible


Now with attachment.

If you want use this code: then you must test him very good in your environment.

If not OK: please give feedback.


Dear Rami sorry for delayed answer I didn't get notice that my question was approved so I didn't check if anybody saw my question...

Thanks for your reply and I'm going to study your solution suggestion and I'll give you feedback right away!


Sorry one error more: the check of "equal segment" use the length of segments.

Attached an new solution that check of the 2 end-point-values of a segment.

The new solution use a async-modus between add-listener and the segment-check.

I think it is more clear what happen and more robust.

© 2022 International GeoGebra Institute