Web links from scrolling field?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Web links from scrolling field?

Post by peter.s » Sun Sep 26, 2010 1:20 pm

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

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Web links from scrolling field?

Post by Klaus » Sun Sep 26, 2010 1:32 pm

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

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Web links from scrolling field?

Post by peter.s » Sun Sep 26, 2010 10:46 pm

Thanks Klaus - I'll give it a try...

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Web links from scrolling field?

Post by peter.s » Tue Sep 28, 2010 9:41 am

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

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Web links from scrolling field?

Post by Klaus » Tue Sep 28, 2010 12:34 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Web links from scrolling field?

Post by bn » Tue Sep 28, 2010 1:04 pm

Hi Klaus,
Hi Petra
????
:)
regards
Bernd

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Web links from scrolling field?

Post by Klaus » Tue Sep 28, 2010 1:30 pm

Oopsie, Freud'sche Fehlleistung/Freudian slip, should of course read "Peter" :oops:

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Web links from scrolling field?

Post by peter.s » Fri Oct 01, 2010 2:54 pm

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

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Web links from scrolling field?

Post by peter.s » Fri Oct 01, 2010 3:07 pm

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??

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Re: Web links from scrolling field?

Post by Janschenkel » Fri Oct 01, 2010 4:45 pm

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Web links from scrolling field?

Post by peter.s » Fri Oct 01, 2010 5:22 pm

That's fantastic. I got it working - thank you so much Jan!

P

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Web links from scrolling field?

Post by Regulae » Fri Oct 01, 2010 6:32 pm

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

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Re: Web links from scrolling field?

Post by Janschenkel » Sun Oct 03, 2010 7:30 pm

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Post Reply