Creating Hypertext Links in Fields

Creating hyperlinks in field objects.

Attached Files

Description:  This tutorial explains how to use the textStyle and textLink properties to create hypertext links within a locked text field.  

Description:  This tutorial explains how to use the textStyle and textLink properties to create hypertext links within a locked text field.  

1.  Launch Revolution and create a new mainstack.

Creating your text field.

Creating your text field.

2.  Create a text field that will contain the text which you wish to make into a hypertext link by either double-clicking one of the field object creation tools on the tools palette or by click-dragging the field object creation tool on the tools palette over to your stack.

Adding text to your text field.

Adding text to your text field.

3.  Enter the following in the text field by either switching to browse/run mode and entering the text directly or by entering it into the "Contents" section of the field's Object Inspector, obtained by first clicking on the field to make it active and then performing the menu command Object -> Object Inspector:

         Click here to go to RunRev's site. -- this is the beginning of the text to enter into the text field

         Click here to go to a card with

         more information. -- this is the end of the text to enter into the text field

 

4.  Using the Object Inspector, name the field "text" or some such thing.  While this step isn't really necessary, it is good practice to give objects names that are easily remembered.

5.  Create a new card (this should be card 2).  Open the message box by performing the menu command Tools -> Message Box.  Using the message box, go back to card 1 by typing the following plus return:

go card 1

 

Setting the textStyle to link.

6.  Open the message box and type the following, followed by a return/enter:

   set the textStyle of word 2 of line 1 of fld "text" to link -- this sets the second word of the first line as having a link textStyle.

This should result in the indicated word having a blue, underlined, link appearance.

 

Linking the link to a destination (website).

7.  Enter the following in the message box, followed by a return/enter:

 set the linkText of word 2 of fld "text" to / "http://www.runrev.com" -- this makes the link, when clicked, open a web browser that opens this URL.

 

8.  Repeat instruction 6, changing the chunk descriptor to reflect the second "here" in the text field.

Linking the link to a destination (a card in your stack).

9.  Repeat instruction 7 but, instead of the URL, give the destination as "card 2" or whatever you have named card 2.

Locking the text field

Locking the text field

10.  Lock the field "text" clicking on it, accessing its Object Inspector palette, and ticking the box titled "Lock text".  

Scripting the Locked Field

Scripting the Locked Field

11.  We will now script the field to handle the links being clicked and directing the user to the desired location.  To do so, select the text field by clicking on it, perform the menu command Object -> Object Inspector, and click on the little triangle on the right which brings up further options, including "Edit Script"; select "Edit Script".  (Alternatively, you can access it directly by using command-e or your systems appropriate keyboard accelerator combination).

12.  In the Script Editor window, enter the following script and click on the "Compile" button in the upper-left corner:

on linkClicked myLink

if myLink contains "http://" then

revGoUrl myLink

else if myLink contains "card" then

go cd 2

end if

end linkClicked

Save and test!

13.  Save your stack by performing the menu command File ->  Save As...

14.  Switch into browse/run mode by clicking on the arrow tool on the Tools Palette, then click on your links to see if they work.

Example Stack

If, for some reason, you'd like a copy of this stack, visit http://jperryl.ecs.fullerton.edu/Hyperlinks.zip

0 Comments

Add your comment

E-Mail me when someone replies to this comment