print #handle, "flush"

This command ensures that drawn graphics 'stick'.  Each time a flush command is issued after one or more drawing operations, a new group (called a segment) is created.  Each segment of drawn items has an ID number.  The segment command retrieves the ID number of the current segment.  Each time a segment is flushed, a new empty segment is created, and the ID number increases by one.  See also the commands cls, delsegment, discard, redraw, and segment.

print #handle, "flush segmentName"

This command ensures that drawn graphics 'stick', and assigns a name to the flushed segment. Each time a flush command is issued after one or more drawing operations, a new group (called a segment) is created. This assigned name can be used in later commands to manipulate the segment.

print #handle, "segment variableName"

This causes the window to set variableName to the segment ID of the currently open drawing segment.  To get the segment ID of the last segment flushed, subtract one.  Segment ID numbers are useful for manipulating different parts of a drawing. 
