#22000/11/22 23:17:41
                            
                                在编程时我们经常用到鼠标的飞越提示,也就是当鼠标停留在某一目标上时就会出现一条小小的提示信息。
在DIRECTOR中也很容易实现这个功能,现就把自己做法贴出来大家一起交流,也希望有其它好方法的高手指点一二。
我用是鼠标实时跟随法。也就是在影片中总有一个文本角色跟随鼠标移动,在不需要显示时把它的blend设为0这样就看不到了,
在要它显示时再设为100它就会出现了。
代码我用现在比较流行的“面向对象(OOP)”的方法来写(这个我也是新学的,现在是第一次用:D)。
首先用 Script Window 按钮新建立一个父脚本角色其中脚本如下:
property HintSprite --提示文本所在的通道
on new me,HspNum --HspNum是提示文本的通道号
  if (Hspnum=void) then HspNum=50 --缺省为第50号通道
  set HintSprite=sprite(HspNum)  
  return me 
end
on DisplayHint me,HintText
  HintSprite.member.text=HintText --设置要出示的提示文本内容
  return
end
on FloweMouse me
  HintSprite.loch = the mouseH-(HintSprite.member.width/2) --跟踪鼠标
  HintSprite.locv = the mousev+16
  if length(Hintsprite.member.text)=0 then
    HintSprite.blend=0  --隐藏
  else
    HintSprite.blend=100  --显示
    if (the mouseH + HintSprite.member.width) > (the stageRight-the stageLeft) then
      --防止提示出右边界
      HintSprite.loch= the stageRight - the stageLeft - HintSprite.member.width
    end if
    if (the mouseH-HintSprite.member.width/2) < 0 then
      --防止提示出左边界
      HintSprite.loch=0
    end if 
    if (the mouseV + HintSprite.member.Height) > (the stageBottom - the stageTop) then
      --防止出下界
      HintSprite.Locv=The MouseV-HintSprite.member.Height
    end if
  end if
  
  return
end floweme 
写完脚本之后要在脚本的 Script cast Member Properties 中将要设为父脚本的脚本类型(type)设为Parent。
接下来要设置提示文本显示用的文本对象,可以用 TEXT 也可以用 Field 在DR8中建议用 TEXT 因为 Field 的中文有问题。
TEXT的 Froming 最好设为 Ajust to fit , WorD wrap  自动换行。字体大小设为14,它的宽度为113(刚好八个汉字).
通道最好放到最下一层,这样才不会被其它的角色遮挡。
设好后就是调用的问题了,由于是用 OOP 所以调用起来就方便而且真观。
要在帧脚本中写:
on exitFrame me 
--这里是设置跟随的,没有它可不行,不然它可不会出现在该出现的地方!!
  set hint1=new(script "hint")  
--将对象IDH号存入变量(这里没有设置提示文本的通道号,自动设为50)
--也可根据实际设置,如   set hint1=new(script "hint",90) 就是通道为90的情况  
  FloweMouse(hint1)  --调用句柄
  go to the frame --循环同一帧,相当于暂停影片。
end
在需要提示的角色内写脚本:
on mouseEnter
 set fhint=new(script "hint")
 displayHint(fhint,"我是提示信息")--出现提示
end mouseEnter
on mouseLeave
    set fhint=new(script "hint")
    displayHint(fhint,"")--清除提示
end mouseLeave
                                
                                
                                
                            
                            
                                
                                    编辑历史:[这消息被flyingbird编辑过(编辑时间2000-11-23 04:29:42)]