Preloading cast members from disk

Note - this article relates to preloading assets from disk. In other words, it relates to using Projectors and delivering your project on CD-ROM. For preloading Shockwave assets, see this article

Preloading cast members can be relatively straightforward using the preload command and/or setting preload mode of casts. However, getting some feedback as the preload occurs (so you can show a progress bar) is a bit more tricky.

One approach is to use the idleLoadtag to tag each cast member before issuing a 'preloadmember' command. This allows you to monitor progress through a list of members to preload. This approach works best when loading several members rather than a few larger members since you can only measure the progress through the list of members, not the progress in loading an individual cast member.

Below is an example parent script to manage loading a list of cast members. You can query the instance of this script to get a percentage of the cast members which have been loaded:

Demo Director 8.5 movie: SIT or ZIP)

-- script "MemberLoadMgr_class"

property myDefaultIdleMode

property myLoadtag

property myIndexMax

property myIndex

property myMemberList

property myTimeout


on new (me, aListofMembers)



  -- start loading if a list is provided here

  if aListofMembers.ilk = #list then me.mLoadMembers(aListofMembers)

  return me


on mDestroy (me)

  if myTimeout.ilk = #timeout then myTimeout.forget()

  myIndex = myIndexMax


  the idleLoadMode = myDefaultIdleMode


on mLoadMembers (me, aListofMembers)

  myMemberList = aListofMembers.duplicate()

  myIndexMax = myMemberList.count

  myIndex = 0

  myTimeout = timeout(me.string).new(0, #nothing, me)

  the idleLoadMode = 3


on mGetPercentageDone (me)

  if myIndexMax > 0 then

    return (float(myIndex)/(myIndexMax))*100


    return 100

  end if



on exitframe (me)

  if idleLoadDone(myLoadtag) then

    if me.mLoadNextMember() = 0 then = VOID


      the idleLoadMode = myDefaultIdleMode

    end if

  end if


on mLoadNextMember (me)

  if myIndex < myIndexMax then

    myIndex = myIndex + 1

    thisMember = myMemberList[myIndex]

    if thisMember.ilk = #member then preLoadMember thisMember

      return myIndex


      return 0

    end if


on mInitClass (me)

  myDefaultIdleMode = the idleLoadMode


on mInitInstance (me)

  uniqueName = string(me).word[4]

  delete the last char of uniqueName

  myLoadTag = symbol(uniqueName)-0

  myTimeout = VOID


Usage example

The following is an example behaviour on progress bar etc

property myLoader

on beginSprite (me)

  myMembers = [member("blah1", member("blah1"), member("blah3")

  myLoader = script("MemberLoadMgr_class").new(myMembers)


on exitframe (me)

  if myLoader.ilk = #instance then

    amntLoaded = myLoader.mGetPercentageDone()

    put "loading " & integer(amntLoaded) & "%"

    if amntLoaded = 100 then


      myLoader = VOID

    end if

  end if

First published 07/06/2005