Page 1 of 1

Web links from scrolling field?

Posted: Sun Sep 26, 2010 1:20 pm
by peter.s
Hi there,

How do I create a link to a website from text in a scrolling field?

I have a body of text in a scrolling field on my card and I want to have a link from the text to a web page - just like if it were a Word doc... you know, blue underlined text = link.

If I copy and paste the text from a Word doc into the appropriate field in the object inspector, the text looks right - complete with blue underlined text, but how do I activate it?

Any help greatly appreciated.

Cheers,

P

Re: Web links from scrolling field?

Posted: Sun Sep 26, 2010 1:32 pm
by Klaus
Hi Peter,

pasting from Word will only give you the right look but not the functionality! 8)

You need to select the text that you want to make a link from and set its text-style to "link".
Then you will have to write a little script for that field like this:

Code: Select all

on linkClicked tLink
   launch url tLink
end linkClicked
See "linkClicked" in the docs (Dictionary) for more info.


Best

Klaus

Re: Web links from scrolling field?

Posted: Sun Sep 26, 2010 10:46 pm
by peter.s
Thanks Klaus - I'll give it a try...

Re: Web links from scrolling field?

Posted: Tue Sep 28, 2010 9:41 am
by peter.s
You need to select the text that you want to make a link from and set its text-style to "link".
I managed to get it working by setting the text-style of a line in the text to "link"
Eg:- set textstyle of line 13 in field…

But this is a bit cumbersome for my application. I have a couple of paragraphs of text with some (4 or 5) url addresses scattered in the text.

Is there some way of selecting the url addresses only? Some way of searching for them and setting them to "link" without me specifying exactly where they are as per the way I've done it above?

Any ideas?

P

Re: Web links from scrolling field?

Posted: Tue Sep 28, 2010 12:34 pm
by Klaus
Hi Petra,

of course you can (and will have to) write a little script to do this!

You could loop through all words!
(http/www.blablal.com/url1.html IS fortunately a word for Rev :))

So you could do something like this (not tested, but you get the picture)

Code: Select all

...
repeat with i = 1 to the num of words of fld "xyz"
  if word i of fld "xyz" starts with "http://" then
    set the textstyle of word i of fld "xyz" to link
  end if
end repeat
...
Or replace WORD(S) with LINE(S), if the urls are in a line each.


Best

Klaus

Re: Web links from scrolling field?

Posted: Tue Sep 28, 2010 1:04 pm
by bn
Hi Klaus,
Hi Petra
????
:)
regards
Bernd

Re: Web links from scrolling field?

Posted: Tue Sep 28, 2010 1:30 pm
by Klaus
Oopsie, Freud'sche Fehlleistung/Freudian slip, should of course read "Peter" :oops:

Re: Web links from scrolling field?

Posted: Fri Oct 01, 2010 2:54 pm
by peter.s
You could loop through all words!
Great! With a little tweaking I got it to work - thanks heaps Klaus!

Now I am trying to get the curser to change to a hand when over the link. I can do it with buttons, but how to do it over a text link?


p.s. Klaus - no worries about the Freud'sche Fehlleistung

Re: Web links from scrolling field?

Posted: Fri Oct 01, 2010 3:07 pm
by peter.s
I'm working on something like this...

Code: Select all

on mouseenter Tword
   if Tword is linktext then
   set the cursor to hand
   end if
end mouseenter Tword
Am I close??

Re: Web links from scrolling field?

Posted: Fri Oct 01, 2010 4:45 pm
by Janschenkel
Try this script in your field:

Code: Select all

on mouseMove
   if the mouseChunk is not empty and the textStyle of the mouseChar contains "link" then
      lock cursor
      set the cursor to hand
   else
      unlock cursor
   end if
end mouseMove

on mouseLeave
   unlock cursor
end mouseLeave
Whenever you move the mouse, it checks if there is text under the mouse, and if its text style contains "link" (that way, it also works if you set it to bold and italic, to name just two styles, in addition to link); and if so, it changes the cursor; if not, it unlocks the cursor.

HTH,

Jan Schenkel.

Re: Web links from scrolling field?

Posted: Fri Oct 01, 2010 5:22 pm
by peter.s
That's fantastic. I got it working - thank you so much Jan!

P

Re: Web links from scrolling field?

Posted: Fri Oct 01, 2010 6:32 pm
by Regulae
Hi all,

If I'm not mistaken, there may be a typo in Jan's elegant script, with "mouseChar" intended to be "mouseCharChunk" or, as an alternative, "mouseChunk", which might confuse future readers of this thread.

Regards,
Michael

Re: Web links from scrolling field?

Posted: Sun Oct 03, 2010 7:30 pm
by Janschenkel
Michael is absolutely right - seems I hadn't pasted the final version that worked in my test stack. It was pretty close, but the correct script is:

Code: Select all

on mouseMove
   if the mouseChunk is not empty and the textStyle of the mouseChunk contains "link" then
      lock cursor
      set the cursor to hand
   else
      unlock cursor
   end if
end mouseMove

on mouseLeave
   unlock cursor
end mouseLeave
Jan Schenkel.