I’ve searched the forum and read the aTbRef documentation. Still, I cannot figure out how to use a numerical attribute value (e.g., $MyNumber) in $Flags in Action Script—adding the attribute value to the $Flags list results in a red flag. It works if I type a hard-coded numerical value, such as 42.
Is there some unique attribute value manipulation that one needs to do to get its value represented in a Flag?
Interesting question based on a mis-presumption (that is obvious only after the fact):
Flags are based on string (text) values.
So, if you need to check the number value and set the appropriate colour then if $MyNumber is intended to map to a red flag:
if($MyNumber==2){
$Flag="red";
};
I think your other misreading of my aTbref notes—though in the light of this they could be clearer, is that the ‘base’ input, i.e. the first argument for a $Flags value, is a colour. The colour value is either a named ‘color’ ($Color) within the current TBX, e.g. ‘blue’, or a hash-prefixed hexadecimal colour code (e.g. #0f0 or #00ff00`). An input of ‘42’, unless you have a named colour of ‘42’ is a non-colour name/definition and so sets the colour value used for undefined/unparseable colour input, which is an orange/red colour.
If you want a $MyNumber value to set a colour, I suggested birther using a dictionary, e.g. key ‘2’ has a value", or use the older look-up table notion. Either way, you map a number to a string, thst latter being one $Flags understands.
Interesting. I’m a litte confused, because this aTbRef entry includes the following example:
#ffd700:F14.black
…where “F14” is rendered as text in the flag
I think I wrongly assumed that I could replace the “F14” with a numerical or string value from an attribute, like so:
#ffd700:$MyString.black
At any rate, thank you for clearing up my confusion. It also occurs to me that I should have included a better explanation of what I was trying to accomplish in my original post.
Point taken. I’ll try and clarify the article a bit. The example code you cite:
Text caption. A period ‘.’ adds a short textual annotation (1-3 characters) on top of any other colour/pattern: A1.red, or 42.green>red, or BZ.yellow$light green. The characters >*+.$%} are treated as literal characters if they are used the first three characters of flag code using the period marker, so +.red draws a plus sign on a red flag.
Text colour. Though text is normally white, a colour may be specified: black:C.lighter blue, or #ffd700:F14.black
Missing from this is that a colour is always needed. So if I set a value of F14 with no other characters, ttbx assumes I want to set the named colour ‘F14’. As this colour is not defined, we get the ‘undefined colour’ value, an organey-red:
Just so I’m clear, using the aforementioned examples, you can’t set the “F14” portion, or the string value, of the flag programatically in Action Code, based on an attribute or variable value, correct?
For example, I can’t do something like this:
function updateFlags(aNote) {
$Flags(aNote) = [black:$MyString(aNote).blue$yellow];
}
Thank you, @mwra, for sharing your detailed analysis; it’s very helpful.
Note: you want the string value of colours (either a literal name or hex code). I used enclosing parens to ensure the string is fully concatenated before it is passed to $Flags.
So yes. I’ve not tried an function but the latter is more of a wrapper to the code setting $Flags and that seems to accept dynamic values, albeit first assembled as single string before being passed to the $Flags atttribute.