(5)将文本演员“mytext”、“text_fanyi”以及背景图片拖放到舞台,如图22.5所示。并给“mytext”附上“txt&sound”行为,行为脚本内容如下:
图片如下:
图22.5 剪辑室
txt&sound行为脚本内容:
global text_num
property sentencelist,sentencenum
property soundmember,readnum,colorchange
on beginsprite me
sentencelist = []
sentencenum = 0
colorchange = 0
member("mytext").text = ""
soundmember = member("ccc")
readnum = 0
member("mytext").font = "System"
member("mytext").fixedlinespace = 22
member("mytext").firstindent = 0
member("mytext").fontstyle = [#plain]
member("mytext").color = rgb(0,0,0)
member("text_fanyi").text = ""
m = member("aaa")
s = m.text
n = length(s)
repeat with i = 1 to n
if s.char[i] = "*" then
delete s.char[i]
add sentencelist,i
end if
end repeat
member("mytext").text = s
n = sentencelist.count
repeat with i = 3 to n
if i mod 2 = 1 then
ch1 = sentencelist[i-1]
ch2 = sentencelist[i] - 1
member("mytext").char[ch1..ch2].color = rgb(0,0,255)
end if
end repeat
if sentencelist[1] > 1 then
ch1 = 1
ch2 = sentencelist[1] - 1
member("mytext").char[ch1..ch2].color = rgb(0,0,255)
end if
m = member("ccc")
puppetsound 1,m
end
on exitFrame me
if soundbusy(1) then
colorchange = 1
t1 = sound(1).currenttime
if readnum = 0 then
t2 = 0
else
t2 = soundmember.cuepointtimes[readnum]
end if
if t1 > t2 then
if soundmember.cuepointtimes.count > readnum then
readnum = readnum + 1
ch1 = sentencelist[readnum*2-1]
ch2 = sentencelist[readnum*2] - 1
if readnum > 1 then
ch3 = sentencelist[readnum*2-3]
ch4 = sentencelist[readnum*2-2]
member("mytext").char[ch3..ch4].color = rgb(0,0,0)
end if
member("mytext").char[ch1..ch2].color = rgb(255,0,0)
member("text_fanyi").text = member("bbb").line[readnum]
end if
end if
else
if soundmember.cuepointtimes.count > 0 then
if colorchange = 1 then
ch1 = sentencelist[readnum*2-1]
ch2 = sentencelist[readnum*2] - 1
member("mytext").char[ch1..ch2].color = rgb(0,0,0)
colorchange = 0
readnum = 0
end if
end if
end if
end
完成效果
运行程序,完成效果如图22.6所示:
图片如下:
图22.6 完成效果