主题:  <文本传递>行为! (一个开始!)

threem

职务:普通成员
等级:2
金币:1.0
发贴:338
#12001/11/15 12:45:14
很偶然的想法产生了一个行为!

用于在两个指定相关文本域间的特定字符的传递!
下载后将<文本传递>.cst复制到director目录下libs文件夹中即可使用!

请大家多提批评!

:)


行为开发说明:
难度:中级
开发时间:五小时!
满意度:79

请 用 过 的 朋 友 在 行 为 区 发 表 用 后 感 !

谢谢!

:)

∏∏∏∏∏∏∏∏∏ 以下为完整代码 ∏∏∏∏∏∏∏∏∏

---《文本传递》行为类简介:
-----《文本传递》行为类将开发更多关于Director文本操作的行为!同时她是完全共享的!
------我们希望众多爱好者来共同努力完善她!
------我们需要每一个批爱好者的参与,请将在使用行为过程中发现以下问题,请与我们联系:

------------- 一、对于你所用的行为有更好的建议,即希望加强某行为的功能!
------------- 二、发现某行为存在缺陷!
------------- 三、发现某些常用操作流程尚未有相关行为的!
------------- 四、你认为对行为类友有益的其他建议!


------联系方式:Three-m@etang.com.cn 或访问:www.aougu.com 讨论


---《文本传递_1》行为简介:
---本行为用于在两个指定相关文本域间的特定字符的传递!
---
---- 版权作者:Three-m
--- 2001.11.13


property canrepeat --标记是否检测重复输出的属性
property alertnews --标记如果用户重复输出。是否弹出警告对话框!
property workmate --确认信息互通精灵号!即目标文本域!
property remains --标记是否保留源字符的属性!
on beginsprite me
workmate=value(workmate.word[1])
end



on mousewithin me --将鼠标停留在的行文字高亮显示!
mouseinline=getline(me)
if mouseinline = 1 then
startChar = 1
else
startChar = (sprite(me.spritenum ).member.text.line[1..mouseinline-1]).length + 2
end if
endChar = (sprite(me.spritenum ).member.text.line[1..mouseinline]).length + 1
hilite char startChar to endChar of field sprite(me.spritenum ).member
end

on getline me --获得鼠标停留所在的行编号!
y = the mouseV - sprite(me.spriteNum).locV+sprite(me.spriteNum).member.scrollTop
lineNum = y/(sprite(me.spriteNum).member.lineHeight)+1
return linenum
end

on mouseup me
if the doubleClick=true then --确认双击之后执行传递流程!
clickedline=getline(me)
num=me.spritenum --寄放源文本精灵编号的局部变量!
clickedtext=sprite(num).member.text.line[clickedline] --获得选定的文本!
if clickedtext<>"" then
doput clickedline,clickedtext,num--执行传递流程的程序!
end if
end if
end




on doput clickedline,clickedtext,num
-------------------------------------------------
--根据用户的自选属性!决定文本输出后是否在源文本域中保留选定文本!
if remains=false then --通过字符与数组的转换来实现将源文本域中的选定文本删除!
listout=texttolist(sprite(num).member.text)
deleteAt listout, clickedline
temptxt=listtotext(listout)
sprite(num).member.text=temptxt
end if


-------------------------------------------------
if workmate<>0 then
---------------------------------------------------------------------
if sprite(workmate).member.text<>"" then
set thelines=the number of lines in sprite(workmate).member.text
---------------------------------------------------------------------
if canrepeat=false then
set repeatrecord=0 --假设没有重复记录!
repeat with lin=1 to thelines
---------------------------------------------------------------------
if sprite(workmate).member.line[lin]=clickedtext then
repeatrecord=1 --标记已经存在重复记录!
---------------------------------------------------------------------
if alertnews=true then alert "对不起!您不能重复选择""e&clickedtext"e
---------------------------------------------------------------------
end if
---------------------------------------------------------------------
end repeat
if repeatrecord=0 then --没有重复记录,允许传递数据!
sprite(workmate).member.line[thelines+1]=clickedtext
end if
else
sprite(workmate).member.line[thelines+1]=clickedtext
end if
---------------------------------------------------------------------
else
sprite(workmate).member.text=clickedtext
end if
---------------------------------------------------------------------
end if
-- 将选定文本输出到目标文本域!
end



on texttolist(thetxt)--字符串数组转换
set templist=[]
set linenums=the number of lines in thetxt
if linenums>1 then
repeat with p=1 to linenums
append templist, thetxt.line[p]
end repeat
else
templist=[thetxt]
end if
return templist
end

on listtotext(thelist) --- 数组字符串转换
if count(thelist)>0 then
set temptxt=thelist[1]
repeat with p=2 to count(thelist)
set temptxt=temptxt&return&thelist[p]
end repeat
else
temptxt=""
end if
return temptxt
end






on isOKToAttach me,SpriteType,spritenum
if sprite(spritenum).member.type= #field then
set menum=sprite(spritenum)
return true
end if
--在用户添加行为时!确保目标精灵为文本域演员精灵!
end isOKToAttach


on getBehaviorDescription me
return \
"本行为用于在两个指定相关文本域间的特定字符传递! " & \
"用户通过鼠标双击来选定、执行传递字符!"
end getBehaviorDescription

on getBehaviorTooltip me
return \
"本行为用于在两个指定相关文本域间的特定字符传递! " & \
"用户通过鼠标双击来选定、执行传递字符!"&\
"通过可选项的搭配!可以实现多种交互传输!"
end getBehaviorTooltip

ON getmemlist
SET memlist=[" 0 -- ( 数据不输出 )"]
REPEAT WITH N=1 TO 1000
IF SPRITE(N).member.TYPE=#field THEN
if SPRITE(N).member.name="" then
append memlist, " "&n&" -- ( Field: "&SPRITE(N).member.membernum&" )"
else

append memlist, " "&n&" -- ( Field: "&SPRITE(N).member.name&" )"
end if
end if
end repeat
return memlist
end




on getPropertyDescriptionList me

return \
[#workmate:[ #comment: "请确认信息互通精灵:",#format:#string,#default: "" ,#range:getmemlist()],\
#remains:[ #comment: "保留源选项:",#format:#boolean,#default: true ],\
#canrepeat:[ #comment: "允许重复输出:",#format:#boolean,#default: false],\
#alertnews:[ #comment: "重复选定时,是否警告:",#format:#boolean,#default: false]]

end getPropertyDescriptionList


编辑历史:[这消息被threem编辑过(编辑时间2001-11-15 12:47:49)]
[这消息被threem编辑过(编辑时间2001-11-15 12:49:12)]