Articles Archive
Articles Search
Director Wiki

Fetching External Media for Shockwave

September 3, 1998
by Alex Zavatone

By far, one of the most promising features in Director 6 is the capability to load media off of the net. By far, one of the most annoying processes in Director 6 has been writing lingo to load media off of the net. Before proceeding, it is imperative to understand the following: Stuff that works at author time will not always work in Shockwave. Case in point with plugin 6.01:

Moral of the preface? Test .dirs and .csts in authoring and test .dcrs and .ccts in shockwave WHEN attempting to load castlibs over the net. In all other circumstances, you should test your .dirs and .csts in shockwave.

How to do it.

Director 6 includes two commands for fetching media off the net that appear to be similar but it is often unclear which one to use when getting media off the net for a Shockwave movie. For Shockwave, preLoadNetThing is the command of choice. This command downloads the desired media into Shockwave's cache folder where it can be accessed locally. On the Mac, this is an invisible folder that can not be opened. On Windows, the folder is the c:/temp folder or the windows/temp folder.

When using preloadNetThing to fetch gifs, jpegs or movs, the procedure is more straightforward than when dynamically loading new castlibs. Why? The procedure should be the same but in Lingo, you can not create a new castlib without going through an unsupported and untested procedure. It may work but.... The standard procedure is to include the desired amount of dummy external castlibs in your movie that you plan on replacing when you run the movie and then change the filename of your castlibs. There is also the movie/castlib typing check to be aware of. When testing a .dir movie, you must use .cst files. But when on the web as a .dcr, you must use .cct files or you will be presented with a rather cryptic error -201 message (or no error message at all!) Using a Mac with OS/8 as a local server is very helpful when testing since you can just drag your files to your local web site without resorting to a modem and FTP.

After getting a grip on the caveats of using downloadable media in Shockwave, the trick is to set up your lingo so that it can download your media without interrupting the flow of the movie. If your audience is on a modem, the users on macs will have your animations skip or pause intermittently as the modem takes part of the processor power. What do you do? Either bear with it or limit your animations till the media has downloaded. But lingo and its repeat loops do not allow many events through, including net events, and this means that you can not use a repeat loop to check whether your loading is done. What I developed is a check based on the stepFrame handler on objects in the actorlist getting executed every frame. Simply put an object in the actorlist and every enterframe, it will automatically check itself for completion. No need to interrupt the movie's flow in the score. The concept here is chock full of buzzwords (autonomous threading... blah blah blah) but it provides the functionality to fetch a castlib, display it and then clean up after itself without affecting score structure or messing up the flow of your movie.

With this concept comes the object structure and a wee parent script. For those of you not yet familiar with these beasties, never fear, you just start the objects up and make sure they have the right info and they'll do the job for you. In fact, when dealing with importing jpegs, gifs and movs, a generic "net done" script is used as the ancestor. In the sample code presented below for the purpose of importing a range of castlibs when your movie starts up, everything is wrapped into one nice little object.

Script: ImportAllCastlibs ¬
-- © Alex Zavatone 1997/1998.
-- For
property pStartCastLib, pEndCastlib, 
Property pUrl, pCurrentCastLib, pSuffix, pNetId
on New me, myUrl
  init me, myUrl
  add (the actorlist, me)
on Init me, myUrl
  set pStartCastLib = 2 
  -- hard coded value specifying the start castlib
  set pEndCastLib = the number of castlibs 
  -- hard coded value specifying the end castlib
  set pCurrentCastLib =  pStartCastLib
  -- check for authortime or runtime
  if the runmode = "author" then 
    set pUrl = myUrl
    set pSuffix = ".cst"
     set pSuffix = ".cct"
     set pUrl = myUrl
  end if
  LoadCast me

on StepFrame me
  if not netDone(pNetId) then return
  set the filename of castlib pCurrentCastLib = Â
   pUrl & (pCurrentCastLib - 1) & pSuffix
  if pCurrentCastLib < pEndCastlib then
    set pCurrentCastLib = pCurrentCastLib + 1
    LoadCast me
    -- when done, delete myself from the actorlist
    deleteOne( the actorList, me)
  end if

on LoadCast me
  preloadNetThing pUrl & (pCurrentCastLib - 1) ¬
    & pSuffix
  set pNetId = getLatestNetId()

To start this code, I execute it in the first line after StartMovie, forcing the rest of my castlibs to load. One would expect this to happen automatically with the new streaming feature of Director 6 but it just didn't happen and I had to write this code. To start this up, you'll need to do a few things:

  1. name the castlibs on your server, 1.cct, 2.cct, 3.cct, etc...
  2. change the hard coded starting and ending castlib values in the Init routine to reflect your needs.
  3. start it up like so: new (script "importcastlibs", the moviepath)

See, this works because when an object is in the actorlist and it has an stepFrame script, the stepFrame script gets executed on every frame. This allows the object to check itself automatically for completion and then start the next castlib. This script could be improved by interleaving the loading of the castlibs. If 2 or 3 are loading at one time, individually they will come in slower the the overall load time is decreased because all the modem bandwidth is being used all the time. What slows down each load is the process of "looking up server, contacting server, waiting for response..." and that has to be done on each HTTP request.

To see this actually working, click GO on the movie below and watch the graphics change as the castlibs load in. Sample movies available for download in Mac or PC formats.

A Director user since 1987, Alex (Zav) Zavatone has worked on the engineering teams for both Director and Shockwave, 4, 5, 6 and 7. Recent investigations find him developing foundation classes for Director with asynchronous process management and other life threatening activities. In its early days, he had something to do with this Internet thing known as "DOUG". A noted ne'erdowell, slacker and laggard, Mr. Zavatone is nonetheless is trusted by children, small animals and the elderly. In his spare time, Mr. Zavatone rehabilitates lame desert trout.

Copyright 1997-2019, Director Online. Article content copyright by respective authors.