Page 1 of 1
error creating hyperlink in field
Posted: Fri Feb 06, 2015 11:49 pm
by labrat
I am trying to create a hyperlink on a word selected in a text field. Here is the code:
Code: Select all
on mouseUp
put the selectedText of field "note"
set the linkText of the selectedText of field "note" to "http://revolution.byu.edu/textfind/TextandFind.php"
end mouseUp
The first line successfully outputs the selected text to the message box (when I comment out the troublesome line).
However, when I try to compile the code, I get the following error: button "Button": compilation error at line 3 (set: missing 'to'), char 28
My instruction appears to be formatted as is the example in the dictionary so I do not understand the error.
Any help is appreciated.
Re: error creating hyperlink in field
Posted: Sat Feb 07, 2015 12:24 am
by FourthWorld
When clicked with the mouse, the text isn't selected per se. See the linkClicked message in the Dictionary - I think that'll make what you want to do super easy.
Re: error creating hyperlink in field
Posted: Sat Feb 07, 2015 12:45 am
by labrat
Sorry if I am being dense but I can't get past
button "Make Link": compilation error at line 3 (set: missing 'to'), char 28
Re: error creating hyperlink in field
Posted: Sat Feb 07, 2015 1:10 am
by FourthWorld
First, my apologies. I was answering a question you didn't ask.

What I wrote would be helpful if you were asking about handling a click on a link, but you're asking about authoring a link. My bad.
The selectedText function returns the string selected. To obtain the character offsets use the selectedChunk.
Also, note that the selectedChunk includes the object reference, so all you'll need is:
Code: Select all
on mouseUp
set the linkText of the selectedChunk to "http://revolution.byu.edu/textfind/TextandFind.php"
end mouseUp
Re: error creating hyperlink in field
Posted: Sat Feb 07, 2015 10:41 pm
by jiml
You may also want to
Code: Select all
set the textstyle of the selectedChunk to "link"
Because your code references the selectedChunk, presumably the field's text is unlocked.
In order to make the link clickable you'll need to:
Code: Select all
set the lock text of fld "note" to true
Re: error creating hyperlink in field
Posted: Sun Feb 08, 2015 4:37 am
by labrat
Thank you both!!

Re: error creating hyperlink in field
Posted: Sun Feb 08, 2015 8:18 pm
by jiml
You're elcome.
But a correction. locktext is one word. (darn autocorrect!)
Code: Select all
set the locktext of fld "note" to true