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:
- Loading .csts into a .dir in authoring works as expected.
- Opening a miaw .dcr and loading .ccts into it during authoring also works.
- Loading .csts into a .dir in Shockwave does not work when serving off a local server and there is no explanation as to why. (You can play them off your local drive if you put all the files in a dswmedia directory.) But loading .ccts into a .dcr in Shockwave does work when serving off a local server.
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 Director-online.com property pStartCastLib, pEndCastlib, Property pUrl, pCurrentCastLib, pSuffix, pNetId on New me, myUrl init me, myUrl add (the actorlist, me) end 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" else set pSuffix = ".cct" set pUrl = myUrl end if LoadCast me end 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 else -- when done, delete myself from the actorlist deleteOne( the actorList, me) end if end on LoadCast me preloadNetThing pUrl & (pCurrentCastLib - 1) ¬ & pSuffix set pNetId = getLatestNetId() end
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:
- name the castlibs on your server, 1.cct, 2.cct, 3.cct, etc...
- change the hard coded starting and ending castlib values in the Init routine to reflect your needs.
- 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.
Copyright 1997-2024, Director Online. Article content copyright by respective authors.