|
主题: 用文本连接时,文本的颜色可编辑吗?
|
 wangy
职务:普通成员
等级:1
金币:0.0
发贴:8
注册:2001/6/8 0:33:59
|
#12001/7/10 19:59:40
用文本连接时,文本的颜色可编辑吗?还是只有兰色一种
|
 Call Me Simon
职务:普通成员
等级:2
金币:2.0
发贴:646
注册:2000/9/19 13:56:51
|
#22001/7/11 5:31:20
The short anwser is YES. The following article is from Updatestage.com 引用:
Director's nifty hyperlink feature is about as flexible as you can get. You can make any word or even letter a hyperlink. You can define the behavior of the hyperlink. You can even add or remove hyperlinks via Lingo. BUT you can't define the color of the hyperlink. Puzzling but true. Fortunately it's possible to use Lingo to recolor your hyperlinks at runtime without disturbing the links or the link data.
The text member property "useHypertextStyles" turns off the mandatory blue formatting, the color change when a link is clicked, and the cursor change when the mouse is over a hyperlink. It does not affect the hyperlink itself. If the user clicks on a hyperlink set up via the text inspector, it still registers a hyperlinkClicked and still passes the hyperlink data to whatever handler has been set up to receive it. So if you turn hyperlinkStyles off, you don't have to reconstruct all of the hyperlinks in Lingo, just the visual changes of the hyperlink when it is clicked or moused over.
The hyperlinks property of a text member stores all of the currently defined hyperlinks in a list that looks like this. Each mini-list contains the start and end char of a hyperlink.
put member("hyper").hyperlinks -- [ [44,68], [88,120] ]
The hyperlinks list contains the positions of all of the hyperlinks, which you can use to recolor and style them after "useHypertextStyles" has been turned off.
member("hyper").useHypertextStyles = FALSE
links = member("hyper").hyperlinks
linkcount = count(links)
repeat with x = 1 to linkcount
oneLink = links[x]
st = oneLink[1]
endd = oneLink[2]
-- change the color of this link to red
member("hyper").char[st..endd].color = rgb(255,0,0)
-- reapply the underline
member("hyper").char[st..endd].fontStyle = [#underline]
end repeat
That takes care of the new hyperlink look but you also have to detect when the cursor is over a hyperlink and change it. You can again use the hyperlinks list to compare the character the mouse is over to the list of hyperlinks to see if it falls within one of them. There isn't any built in function to return what character the mouse is over, but you can use locToCharPos with the mouseH and mouseV to find out.
on mouseWithin me
-- The mouseLoc is relative to the top/left of the
-- stage so you must convert it to the loc relative
-- to the top/left of the text member
adjustedH = the mouseLoc[1] - sprite(spritenum).rect[1]
adjustedV = the mouseLoc[2] - sprite(spritenum).rect[2]
-- Returns the char the mouse is over
mouseC = locToCharPos(member("hyper"),point(adjustedH,adjustedV))
-- The isHyperChar handler compares the mouse char to the
-- list of hyperlinks to see if it is inside one if isHyperChar(me) = TRUE then
cursor([member("hand"),member("hand mask")])
else
cursor -1
end if
end
Once you have the character number the mouse is over, you compare it to the list of hyperlinks to see if it falls within a hyperlink
on isHyperChar me,mouseChar
links = member("hyper").hyperlinks repeat with oneLink in links
stChar = oneLink[1]
endChar = oneLink[2]
if stChar > mouseChar then
-- first hyperlink starts after the mouse char
exit repeat
else if mouseChar >= stChar then
if endChar >= mouseChar then
-- mouseChar is inside a hyperlink
return TRUE
end if
end if
end repeat
return FALSE
end
编辑历史:[这消息被flyingbird编辑过(编辑时间2001-07-11 05:48:12)] [这消息被flyingbird编辑过(编辑时间2001-07-11 05:51:23)]
|
 koala_5d
职务:普通成员
等级:2
金币:1.0
发贴:189
注册:2000/12/25 19:27:07
|
#32001/7/11 19:01:20
这个东东能调通吗 :) member("hyper").useHypertextStyles = FALSE links = member("hyper").hyperlinks linkcount = count(links) repeat with x = 1 to linkcount oneLink = links[x] st = getat(oneLink,1) endd = getat(oneLink,2)
- change the color of this link to red
member("hyper").char[st..endd].color = rgb(255,0,0) -- reapply the underline member("hyper").char[st..endd].fontStyle = [#underline] end repeat
编辑历史:[这消息被koala编辑过(编辑时间2001-07-11 19:04:18)] [这消息被koala编辑过(编辑时间2001-07-11 19:05:22)] [这消息被koala编辑过(编辑时间2001-07-11 19:05:41)] [这消息被koala编辑过(编辑时间2001-07-11 19:06:08)]
|