Filling Empty Cast Members

Date:    Fri, 23 Feb 1996 19:13:12 -0800
From:    Miles Lightwood <miles@RHYTHM.COM>
Subject: Re: Filling empty cast cells as runtime

>I want to create a indeterminant number of cast members at runtime from
>scratch.  That means that I have an empty cell in the Cast window - lets
>call it number 15.
>I want to give it a name, a castType, a content and some other things as
>well.  I would like to do all of this with a projector or, worst  case, in a
>shared cast.  I can't figure out how to get the process started.  Attempting
>to set the castType, putting something in it, giving it a name, all fail.
>Any ideas?
The castType of cast property cannot be set. The workaround is to have sample cast members of all castTypes that you duplicate programatically. Here's a sample routine that uses a prop list of these. Fill in the cast numbers for each "sample cast" value before using.
on CreateCast typeOfCast, newCastName
  set errStruct = []
  set castList = [#digitalVideo:"sample dv cast", #bitmap: "sample bitmap
cast", #button:"sample button cast" ,#filmLoop:"sample film loop cast",
#movie:"sample director movie cast", #palette:"sample palette cast",
#picture:"sample picture cast", #script:"sample script cast",
#shape:"sample shape cast", #sound:"sample sound cast",#text:"sample text
cast"]

  if voidP(typeOfCast) then set typeOfCast = #button
  if voidP(newCastName) then set newCastName = "Please name me"
  if NOT symbolP(typeOfCast) then add(errStruct,"not symbol")
  if NOT stringP(newCastName) then add(errStruct,"not string")
  if count(errStruct) > 0 then return errStruct
  set newCast = findEmpty(cast the number of castmembers)


  duplicate(cast getAProp(castList,typeOfCast), newCast)
  set the name of cast newCast = newCastName
end CreateCast
Calling examples:
  CreateCast(the castType of cast (the castNum of sprite 4), "I'm new")
  CreateCast(#button, "I'm new")
  CreateCast(the castType of cast 12, "I'm new")
  CreateCast()

It's not bullet-proof, but it'll get you started.