how to adress the object name and not the number?

Bill Marriott wjm at wjm.org
Thu Apr 19 20:13:49 EDT 2007


The recommendation to name objects starting with a letter and then a number 
is simply a "must" because as others have pointed out there can be ambiguity 
when referencing objects named with simply a number. Two additions to the 
excellent ideas:

1) Remember that the object number always refers to its layer. Lower-numbers 
are below higher-numbered ones.

2) I have found it very helpful to insert a space before the prefix and the 
number when naming objects sequentially -- e.g.: "Cell 1" rather than 
"Cell1" -- because then it's a lot easier to find out what number you've 
given that object using Rev's "word" chunk later on.

For example, suppose you've created an array of fields this way:

  put "Qty,Part Number,Description,Unit Price,Extended Price" into 
theHeaders
  repeat for each item columnName in theHeaders
        repeat with i = 1 to 20
      put columnName && i into thisCell -- the && concatenates with a space 
between
      create fld thisCell
      set the rect of fld thisCell to \
          startLefts[columnName],rowHeight * 
(i-1),startLefts[columnName]+colWidths[columnName],rowHeight * i
      set the lockText of fld thisCell to true
    end repeat
  end repeat

(Leaving out setup of the arrays) Then, when someone clicks on one of the 
cells, you can hilight the entire row very simply with this script in the 
group:

on mouseup
   put the last word of the short name of the target into theLine
   repeat for each item columnName in theHeaders
      put columnName && theLine into thisCell
      set the backgroundColor of fld thisCell to yellow
   end repeat
end mouseup

or, less verbosely,

on mouseup
  repeat for each item c in theHeaders
    set  fillBack of fld (c && last word of short name of target) to yellow
  end repeat
end mouseup

By using "the last word" you've gotten the number of the corresponding 
elements painlessly. 





More information about the use-livecode mailing list