--      Flash动画滑动条程序
--        注意： * 本行为必须添加给滑动块精灵
--               * Flash精灵的编号已经自动生成（最好不要修改）
--               * 滑动条的注册点的位置最好设置在左边

property Ppress  -----判定鼠标按下时的状态，1：表示按下；0：表示松开。
property Vlong
property PlayNow
property Plist
property SwfMems
property mouseLh  ----当鼠标按下时，用于记录鼠标的横坐标
property StartLoc
property sliderBar  ------滑杆所在的通道号
property Myspri
property MySwfSpri  ------Flash精灵的编号
property HwkGoNext

-----------------------  外部调用指令  ----------------------
--------------sendallsprites(#GoSkipSwf,HowD)  
--------------HowD为跳转的数值，-1为倒转1个；+2为快进2个。
on GoSkipSwf me,HowD 
  PlayPlan=PlayNow+HowD
  if ((PlayPlan>0)and(PlayPlan<=count(Plist))) then
    PlayNow=PlayNow+HowD
    sprite(MySwfSpri).member=member(Plist[PlayNow][1])  
    sprite(MySwfSpri).frame=0
  end if 
end
--------------sendallsprites(#getPlayNowNumber)
--------------返回当前播放flash的编号！
on getPlayNowNumber me 
  return PlayNow
end
-------------------------------------------------------------
on beginsprite me
  Myspri=me.spritenum
  Vlong=sprite(sliderBar).width*1.00
  Ppress=0
  PlayNow=1
  SwfMems=value(SwfMems)
  Plist=SetPlist(SwfMems)  
  puppetSprite Myspri, true 
  sprite(MySpri).loch=sprite(sliderBar).loch
end

on mouseenter me
  sprite(MySpri).cursor=260
end

on mouseleave me
  sprite(MySpri).cursor=-1
end

on mousedown me
  Ppress=true
  MouseLh=the mouseh
  StartLoc=sprite(MySpri).loc
end

on mouseup me
  sprite(MySpri).cursor=260
  Ppress=0
end

on mouseupoutside me
  sprite(MySpri).cursor=-1
end

on exitframe me
  if the mouseDown then
    sprite(MySpri).cursor=290
    --
  else
    Ppress=0
  end if  
  if Ppress then
    TraceMouse me
    --    put SwfToLoc(me)
    PlayNow=SwfToLoc(me)[1]
    sprite(MySwfSpri).member=member(Plist[PlayNow][1])
    sprite(MySwfSpri).frame=integer(sprite(MySwfSpri).member.frameCount*SwfToLoc(me)[2])
    --    sprite(MySpri).loch=the mouseh
  else
    PlayListSwf
    sprite(MySpri).loch=sprite(sliderBar).loch+Plist[PlayNow][3]+Plist[PlayNow][4]*1.00*sprite(MySwfSpri).frame/Plist[PlayNow][2]
  end if
end

on endsprite me
  puppetSprite MySpri, false  
end

on SetPlist SwfMems 
  ListTemp=[]  
  if listP(SwfMems) then 
    --
  else
    alert "对不起！请确认行为属性设置中-演员编号-项的输入为列表形式！"&\
return&"例如：[1,2,3,4]"
    halt
  end if  
  FraPer=0
  FraPerLi=[]
  SwfNums=count(SwfMems)
  repeat with Dg=1 to SwfNums
    ListTemp2=[]
    append ListTemp2,SwfMems[Dg]
    append ListTemp2,member(SwfMems[Dg]).frameCount    
    append ListTemp,ListTemp2
    append FraPerLi,FraPer
    FraPer=FraPer+member(SwfMems[Dg]).frameCount    
  end repeat  
  repeat with gg=1 to SwfNums
    append ListTemp[gg],Vlong*1.00*FraPerLi[gg]/FraPer
    append ListTemp[gg],Vlong*1.00*ListTemp[gg][2]/FraPer
  end repeat  
  --  put ListTemp
  return ListTemp
end

on PlayListSwf
  if sprite(MySwfSpri).frame=sprite(MySwfSpri).member.frameCount then    
    if PlayNow>=count(Plist) then
      if HwkGoNext=false and HwkGoNext=void then
        --当Flash播放完时回到第一帧
        sprite(MySpri).loch=sprite(sliderBar).loch
        sprite(MySwfSpri).hold()
        sprite(MySwfSpri).frame=1
      else
        go the frame + 1
      end if
        abort
    else      
      PlayNow=PlayNow+1
      sprite(MySwfSpri).member=member(Plist[PlayNow][1])
    end if
  end if
end

on SwfToLoc me
  DistSwf=0
  GoDist=sprite(MySpri).loch-sprite(sliderBar).loch
  case true of
    (GoDist>=Vlong):      
      sprite(MySpri).loch=sprite(sliderBar).loch+vlong
      return [count(Plist),(Vlong-Plist[count(Plist)][3])*1.00/Plist[count(Plist)][4]]
    (GoDist<0):
      sprite(MySpri).loch=sprite(sliderBar).loch
      return [1,(GoDist-Plist[1][3])*1.00/Plist[1][4]]
    otherwise:
      repeat with DD=1 to count(Plist)
        if (GoDist-Plist[DD][3])<Plist[DD][4]   then
          return [DD,(GoDist-Plist[DD][3])*1.00/Plist[DD][4]]
        end if    
      end repeat      
  end case    
end

on tracemouse me
  MoveX=the mouseh-mouseLh
  sprite(MySpri).loch=StartLoc[1]+MoveX
end

on getPropertyDescriptionList me
  ----自动获取Flash精灵的编号
  set SwfSprites=[]
  ----遍历 1 到 100 号精灵通道，寻找Flash精灵
  repeat with spritenum=1 to 100
    case sprite(spritenum).member.type of
      (#flash):
        append SwfSprites,spritenum
    end case
  end repeat
  ----------------------------
  pro=[:]
  setaprop pro,#SwfMems,[ #comment: "请输入swf的成员编号（例如：[1]或[1,2,3]）:",#format:#string,#default: [1] ]
  setaprop pro,#HwkGoNext,[ #comment: "是否需要跳到下一帧:",#format:#boolean,#default:false]
  setaprop pro,#sliderBar,[ #comment: "滑动条精灵的定位:",#format:#integer,#default:1,#range: [#min:0,#max:the lastChannel]]
  setaprop pro,#MySwfSpri,[ #comment: "受控制的flash精灵的定位:",#format:#string,#default: 1, #range:SwfSprites]
  return pro 
end getPropertyDescriptionList