What does preloadNetThing look like in action?
The preloadNetThing and downloadNetThing commands differ in a few ways:
-- preloadNetThing can be used in either Shockwave or Projectors, and will store downloaded assets in either the browser's cache folder or the Projector's cache folder.
-- downloadNetThing can be used in Projectors, but not in browser, and it will download the asset to a named location on the hard drive.
PreloadNetThing is more generally useful than downloadNetThing, because it can be used in multiple environments and because it doesn't require tracking a particular file on disk. PreloadNetThing also lets you consistently refer to this cached media by its URL. Both have their purposes, but preloadNetThing will likely be used more than downloadNetThing.
The following simple behavior shows one way to preload and link to a distant graphic. First the command is issued, and then the routine regularly checks for whether the retrieval operation is finished, before finally linking to the distant requested graphic. The following example cannot be used as-is in all intended designs but shows one way of using this type of command across the web.
-- Quick'n'easy image linker. Trigger it by a "sendSprite" or "sendAllSprites" -- with the message "GetNetImage" and the URL. If the URL doesn't exist you'll -- receive a message routed to the Message Window. -- -- The ScriptError handling is a generic one, that here handles two cases. -- The stepFrame method allows for self-contained and asynchronous polling. -- -- History: -- 9/11/97 jd Cleaned up a bit, submitted to KB. -- 7/ 9/97 jd Written, posted to DIRECT-L
property spriteNum, myMember, myNetID, myURL
on beginSprite me set myMember to the member of sprite spriteNum if (the type of myMember <> #bitmap) then ScriptError(me, #invalidMember) end
on GetNetImage me, whatURL set myURL to whatURL set myNetID to preloadNetThing(myURL) add the actorList, me end
on stepframe me if netDone(myNetID) then if netError() = "OK" then set the fileName of myMember to myURL else ScriptError (me, #retrievalError) deleteOne the actorList, me end if end
-- General error-handling routine: on ScriptError me, errorType case (errorType) of #invalidMember: alert "Sorry, this Get Net Image behavior is for graphics only." halt #retrievalError: put "Couldn't get the URL, error code "& netError(myNetID) &"." otherwise: put "Unknown error called from script." end case end
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
