|
Prev: Director Player Error
Next: Page turning effect
From: Zaffer36 on 23 Mar 2006 19:38 i want to attach a bit of code that when i click it will swap the current sprite on stage to a random cast member and also alter its colour, height and width... any ideas? ta!!! :D:D:D:D:D:D
From: openspark on 24 Mar 2006 04:28 The short answer is... vCastLibNum = random(the number of castLibs) vMemberNum = random(the number of members of castLib vCastLibNum) sprite(the currentSpriteNum).member = member(vMemberNum, vCastLibNum) ... but this might attempt to set the member of the sprite to an empty member, or to a script, so it is not reliable. I assume that you want this to work in conjunction with your genotype and phenotype movie, and that you would want to select a random eye, say, or a random leg. If so, then I suggest that you create a separate castLib for each feature: all the eye bitmaps in a castLib called "Eyes", for example. Then you can use the following handler to obtain a random cast member of a given type from a given cast: on GetRandomMember(aCastLib, aType) ---------------------------------- -- INPUT: <aCastLib> should be a string castLib name or integer -- castLib number. If not, a castLib will be chosen at -- random -- <aType> may be a symbol member type, such as #bitmap or -- #filmLoop. If not, any member type (excluding #empty) -- will be considered valid. -- NOTE 1: The order of the parameters is not important. -- NOTE 2: If no castLib is defined, and a member type is given, -- this handler may need to search recursively through all -- the castLibs for suitable member. In this case, a third -- (undeclared) parameter will be used to indicate which -- castLibs have not yet been searched. -- OUTPUT: Returns a random member {from the given castLib} {of the -- given type}, or the error symbol #noSuitableMemberFound -------------------------------------------------------------------- vCastCount = the number of castLibs -- <Check validity of parameters> case ilk(aCastLib) of #integer: if aCastLib < 0 or aCastLib > the number of castLibs then -- Invalid castLib number. Choose a castLib at random. aCastLib = 0 end if #string: repeat with i = 1 to vCastCount if castLib(i).name = aCastLib then -- We've found a castLib with a matching name aCastLib = i exit repeat end if end repeat if not i then -- Invalid castLib name. Choose a castLib at random. aCastLib = 0 end if #symbol: -- Use this first parameter for aType if appropriate. case ilk(aType) of #integer, #string: -- The order of parameters is inversed return GetRandomMember(aType, aCastLib) #symbol: -- Leave aType as it is aCastLib = 0 otherwise: -- Adopt the symbol as aType aType = aCastLib end case otherwise: aCastLib = 0 end case if not symbolP(aType) then -- Choose any type aType = 0 end if -- </Check validity> if not aCastLib then -- No valid castLib given. vCastLibs = param(3) -- undeclared parameter used recursively if ilk(vCastLibs) <> #list then -- No castLibs have yet been tested vCastLibs = repeat with i = 1 to vCastCount vCastLibs.append(i) end repeat end if -- Choose a castLib at random from those that have not yet been -- tested. vCount = vCastLibs.count vIndex = random(vCount) aCastLib = vCastLibs vCastLibs.deleteAt(vIndex) -- so it can't be chosen again end if vMemberCount = the number of members of castLib(aCastLib) -- Make a list of suitable members, excluding #empty members vMemberList = repeat with vMemberNum = 1 to vMemberCount vMember = member(vMemberNum, aCastLib) vType = vMember.type if not aType then if vType <> #empty then vMemberList.append(vMember) end if else if aType = #graphic then -- Allow any non-script members case vType of #script, #empty: -- Ignore this member otherwise: vMemberList.append(vMember) end case else if vType = aType then vMemberList.append(vMember) end if end repeat vMemberCount = vMemberList.count if not vMemberCount then -- No members of the given type where found in the chosen cast if listP(vCastLibs) then -- The castLib was chosen at random if vCastLibs.count then -- Try again, choosing from a different cast return GetRandomMember(0, aType, vCastLibs) else return #noSuitableMemberFound end if else return #noSuitableMemberFound end if end if vIndex = random(vMemberCount) vMember = vMemberList return vMember end GetRandomMember To use this: vMember = GetRandomMember("Eyes", #bitmap) if ilk(vMember, #member) then sprite(the currentSpriteNum).member = vMember end if
|
Pages: 1 Prev: Director Player Error Next: Page turning effect |