Director Web : OOPs

Parent Scripts to Control Buttons

The example below uses parent scripts to change buttons appearance.

--movie script START
on startMovie
  buildPoetryButtons
end startMovie
 
on buildPoetryButtons
  global gPoetryButtons
  if voidP(gPoetryButtons) then
    set gPoetryButtons to []
    addAt gPoetryButtons, 2, pB(2,"PA1.PIC","PA1R.PIC","PA1P.PIC","nextPage")
    addAt gPoetryButtons, 3, pB(3,"PA2.PIC","PA2R.PIC","PA2P.PIC","prevPage")
    addAt gPoetryButtons, 4, pB(4,"PE.PIC","PER.PIC","PEP.PIC","hearPoem")
    addAt gPoetryButtons, 5, pB(5,"PT.PIC","PTR.PIC","PTP.PIC","retrace")
    addAt gPoetryButtons, 6, pB(6,"PC.PIC","PCR.PIC","PCP.PIC","contents")
    addAt gPoetryButtons, 7, pB(7,"PL.PIC","PLR.PIC","PLP.PIC","prevPoem")
    addAt gPoetryButtons, 8, pB(8,"PR.PIC","PRR.PIC","PRP.PIC","nextPoem")
  end if
end buildPoetryButtons
 
on pB c,n,r,p,sc
  return birth(script "bt",c, n,r,p,sc) --saves space
end pB
--movie script END
 
-- parent script "bt" START
--  button trios
property myChannel, myNormal, myRollover, myPressed, myScript
on birth me,sp, no, ro, pr,sc
  set myRollover to (the number of cast ro)
  set myPressed to (the number of cast pr)
  set myNormal to (the number of cast no)
  set myChannel to integer(sp)
  set myScript to sc
  return me
end
 
on rollo me
  puppetSprite myChannel,TRUE
  set the castNum of sprite myChannel to myRollover
  updateStage
  puppetSprite myChannel, false
end
 
on press me
  puppetSprite myChannel,TRUE
  set the castNum of sprite myChannel to myPressed
  updateStage
  puppetSprite myChannel, false
end
 
on norm me
  puppetSprite myChannel,TRUE
  set the castNum of sprite myChannel to myNormal
  updateStage
  puppetSprite myChannel, false
end
 
on doScript me
  do myScript
end
 
-- parent script END
 
--frame script START
on idle
  showhilite gPoetryButtons,2,8
  go to the frame
  pass
end idle
 
on showHilite btnList, firstC, lastC
  put firstC-1 into offfset  ---first entry in list not always sprite 1
  repeat with i = lastC down to firstC
    if rollOver(i) then
      put getAt(btnList,i-offfset) into it
      rollo(it)
      updateStage
      repeat while rollOver(i)
        if the mouseDown then
          press(it)
          doScript(it)
          exit
        end if
      end repeat
     norm(it)
    end if
  end repeat
end showHilite
-- frame script END
 

 ( / Chuck Kuske
 (/  The Voyager Company
 (\  578 Broadway, #406
 ( \ NY, NY 10012-3225