error creating hyperlink in field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
labrat
Posts: 32
Joined: Mon Dec 29, 2014 6:17 pm

error creating hyperlink in field

Post by labrat » Fri Feb 06, 2015 11:49 pm

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: error creating hyperlink in field

Post by FourthWorld » Sat Feb 07, 2015 12:24 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

labrat
Posts: 32
Joined: Mon Dec 29, 2014 6:17 pm

Re: error creating hyperlink in field

Post by labrat » Sat Feb 07, 2015 12:45 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: error creating hyperlink in field

Post by FourthWorld » Sat Feb 07, 2015 1:10 am

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jiml
Posts: 339
Joined: Sat Dec 09, 2006 1:27 am

Re: error creating hyperlink in field

Post by jiml » Sat Feb 07, 2015 10:41 pm

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

labrat
Posts: 32
Joined: Mon Dec 29, 2014 6:17 pm

Re: error creating hyperlink in field

Post by labrat » Sun Feb 08, 2015 4:37 am

Thank you both!! :D

jiml
Posts: 339
Joined: Sat Dec 09, 2006 1:27 am

Re: error creating hyperlink in field

Post by jiml » Sun Feb 08, 2015 8:18 pm

You're elcome.

But a correction. locktext is one word. (darn autocorrect!)

Code: Select all

set the locktext of fld "note" to true

Post Reply