User Guide

176 Chapter 10: Events and Messages
on hyperlinkClicked
Usage
-- Lingo syntax
on hyperlinkClicked me, data, range
statement(s)
end
// JavaScript syntax
function hyperlinkClicked(data, range) {
statement(s);
}
Description
System message and event handler; used to determine when a hyperlink is actually clicked.
This event handler has the following parameters:
me Used in a behavior to identify the sprite instance
data The hyperlink data itself; the string entered in the Text inspector when editing the text
cast member
range The character range of the hyperlink in the text (It’s possible to get the text of the
range itself by using the syntax member Ref.char[range[1]..range[2]]
This handler should be attached to a sprite as a behavior script. Avoid placing this handler in a
cast member script.
Example
This behavior shows a link examining the hyperlink that was clicked, jump to a URL if needed,
then output the text of the link itself to the message window:
-- Lingo syntax
property spriteNum
on hyperlinkClicked(me, data, range)
if data starts "http://" then
gotoNetPage(data)
end if
currentMember = sprite(spriteNum).member
anchorString = currentMember.char[range[1]..range[2]]
put("The hyperlink on"&&anchorString&&"was just clicked.")
end
// JavaScript syntax
function hyperlinkClicked(data, range) {
var st = data.slice(0,7);
var ht = "http://";
if (st = ht) {
gotoNetPage(data);
}
var currentMember = sprite(this.spriteNum).member;
var r1 = currentMember.getPropRef("char", range[1]).hyperlinkRange;
var a = r1[1] - 1;
var b = r1[2];
var st = new String(currentMember.text);
var anchorString = st.slice(a, b);
put("The hyperlink on " + anchorString + " was just clicked.");
}