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


---INTERFACE

on new (me, aListofMembers)
  me.mInitClass()
  me.mInitInstance()
  -- start loading if a list is provided here
  if aListofMembers.ilk = #list then me.mLoadMembers(aListofMembers)
  return me
end

on mDestroy (me)
  if myTimeout.ilk = #timeout then myTimeout.forget()
  myIndex = myIndexMax
  cancelIdleLoad(myLoadtag)
  the idleLoadMode = myDefaultIdleMode
end

on mLoadMembers (me, aListofMembers)
  myMemberList = aListofMembers.duplicate()
  myIndexMax = myMemberList.count
  myIndex = 0
  myTimeout = timeout(me.string).new(0, #nothing, me)
  the idleLoadMode = 3
end

on mGetPercentageDone (me)
  if myIndexMax > 0 then
    return (float(myIndex)/(myIndexMax))*100
  else
    return 100
  end if
end

---PRIVATE

on exitframe (me)
  if idleLoadDone(myLoadtag) then
    if me.mLoadNextMember() = 0 then
      myTimeout.target = VOID
      myTimeout.forget()
      the idleLoadMode = myDefaultIdleMode
    end if
  end if
end

on mLoadNextMember (me)
  if myIndex < myIndexMax then
    myIndex = myIndex + 1
    thisMember = myMemberList[myIndex]
    if thisMember.ilk = #member then preLoadMember thisMember
      return myIndex
    else
      return 0
    end if
end

on mInitClass (me)
  myDefaultIdleMode = the idleLoadMode
end

on mInitInstance (me)
  uniqueName = string(me).word[4]
  delete the last char of uniqueName
  myLoadTag = symbol(uniqueName)-0
  myTimeout = VOID
end

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)
end

on exitframe (me)
  if myLoader.ilk = #instance then
    amntLoaded = myLoader.mGetPercentageDone()
    put "loading " & integer(amntLoaded) & "%"
    if amntLoaded = 100 then
      myLoader.mDestroy()
      myLoader = VOID
    end if
  end if
end
Last updated 25th July, 2006

© 2006 MeccaMedialight. Site Powered by Wrangler 8.