Finding an item in an array |
The most interesting code in the program is the one to determine if the point clicked is inside any of the objects. See indexOf. Notice that if pt is in several elements, selected will only refer to the last of these. It does this by searching from the end of the list backwards until it finds the item or runs through all the elements.
Having this method makes it easy to change the color of an item on the screen and relatively easy to delete one.
Finding an item in an array |