--preloadNetThing Behavior script
--chris walcott
--macromedia director development
--
--version history
--1.0 2/13/97
--1.1 9/26/97 - update and bug fixes.
--1.2 11/24/97 - added Go To Marker and Set preloadDone flag.
--1.3 12/11/97 - added ability to work with save as java xtra.
--INTRODUCTION:
--This behavior can be used to as a general purpose preloadNetThing script.
--The behavior is assigned to a frame Script. With this behavior you can perform a series of preloadNetThing commands. The behavior will process 4 streams at a time until done. When the preloading is completed, you can choose between three different actions.
--Go To Marker sends you to a marker specified in the custom property dialog.
--Autoload Page performs a gotoNetpage on the URL specified in the custom property dialog.
--Set preloadDone to TRUE sets the global variable "preloadDone" to TRUE and progresses to the next frame. It is then up to the author to catch the flag in a frame script to take further action.
--REQUIRED CAST MEMBER. You will have to create a named field cast member to hold the list of URL"s that you want to preload. The list has to be delimited with a * character. This is so the behavior will work with
--the "Save As Java Xtra". An example list:
--http://www.foo.com/media/image1.gif*http://www.foo.com/media/image2.gif
--Do not use quotations. Do not bracket the list.
--
--CUSTOM PROPERTIES:
--"Member Name of URL List" - this is the field that will contain the list
--of URL"s that are to be preloaded. Use the Score channel number of the field.
--"Output Status" - If TRUE, status lines will print to the message window.
--"Action" - If set to "Go To Marker", the playback head will advance to the
--next marker when preloading is done. If set to "AutoLoad", a preloadNetThing
--will be performed on the URL provided in the next property field.
--if set to "Set preloadDone flag TRUE", a global flag will be set allowing you
--to take whatever action you wish and the play head will progress to the next
--frame. Make sure to reset the flag to FALSE after the action is taken.
--"Name of Marker" - if Action is set to "Go To Marker", this is the marker the
--movie goes to.
--"Target URL" - if Action is set to "Autoload Page", a gotoNetPage operation
--will be performed on this URL.
property pListURLs -- field containing URL's to preload
property pDebug -- if TRUE status of preload will print to message window
property pAction -- property determins what action will take place when preload done
property pMarker -- the name of the maker the movie goes to if Action = Go To Marker
property pURL -- which URL is called if Action = "AutoLoad Page"
property pInitializeDone -- flag set to TRUE when initializeNetList is done
property pWaitingList -- list of URL's waiting to be retrieved
property pDispatchedListURL -- list of preloaded URL's
property pDispatchedListNetID -- list of preloaded URL net ID's
on getPropertyDescriptionList
set description = [:]
addprop description, #pListURLs, [#default: "", #format: #integer, ¬
#comment: "Member name of URL list:"]
addprop description, #pDebug, [#default: 0, #format:#boolean,¬
#comment: "Output status to message window:"]
addprop description, #pAction, [#default: "Go To Marker", #format:#symbol,¬
#comment: "Action when PreloadNetThing Done:", ¬
#range: ["Go To Marker","Set PreloadDone flag TRUE","AutoLoad Page" ]]
addprop description, #pMarker, [#default: "", #format: #string, ¬
#comment: "Name of Marker for Go To Marker:"]
return "PreloadNetThing Behavior. A NetLingo behavior script that can ¬
be assigned to a frame script. Use this behavior to perform a series of ¬
preloadNetThing commands from a predefined list. Playhead loops on the frame ¬
until preloading is done. Choose between going to a marker, autoloading a ¬
browser page or setting a global variable flag to TRUE, once preloading is done."
end
on beginSprite me
global preloadDone
set pInitializeDone = FALSE
set preloadDone = FALSE
preLoadMember pListURLs
end
on exitFrame me
global preloadDone
if NOT pInitializeDone = TRUE then
initializeNetList
cursor 4
set pInitializeDone = TRUE
end if
if NetDoneList() > 0 then
go to the frame
else
case (pAction) of
"AutoLoad Page":
cursor 0
gotoNetPage pURL
"Go To Marker":
go to pMarker
cursor 0
"Set PreloadDone flag TRUE":
set preloadDone = TRUE
go to the frame + 1
end case
end if
end
on initializeNetList me
-- initialize dispatched lists
set pDispatchedListURL = []
set pDispatchedListNetID = []
-- build pWaitingList
set pWaitingList = []
set stringDelimiter = "*"
set m = member pListURLs
if the type of m = #field then
set t = the text of field m
set done = false
repeat while not done
set o = offset( stringDelimiter, t )
set l = length( t )
set currChunk = char 1 to o-1 of t
if o = 0 then
set currChunk = t
set done = true
else if o < l then
set t = char o+1 to l of t
else
set done = true
end if
add pWaitingList, currChunk
end repeat
end if
if pDebug = TRUE then
put "List of assets to preload" & RETURN & pWaitingList & RETURN
end if
end
on netDoneList me
-- check the dispatch list for assest that have arrived
repeat with iListAsset = 1 to count( pDispatchedListURL )
-- if the asset has arrived
if NetDone( getAt( pDispatchedListNetID, iListAsset ) ) then
if pDebug = TRUE then
put "Asset Received:" & getAt( pDispatchedListURL, iListAsset )
end if
-- remove if from the dispatch list
deleteAt pDispatchedListURL, iListAsset
deleteAt pDispatchedListNetID, iListAsset
end if
end repeat
-- check the dispatch and waiting list: how many things
-- can we preload? Current stream limit is set to 4
set iCountDispatch to min( count( pWaitingList ), 4 - count( pDispatchedListURL ) )
repeat with iFreeSpot = 1 to iCountdispatch
-- start the preloadNetThing operation on the next waiting asset
set getMe = getAt( pWaitingList, 1 )
if pDebug = TRUE then
put "Asset Preloading" getMe
end if
preloadNetThing getMe
-- move the asset to the dispatched list
append pDispatchedListURL, getAt( pWaitingList, 1 )
append pDispatchedListNetID, getLatestNetID()
-- remove the asset from the waiting list
deleteAt pWaitingList, 1
end repeat
-- check the dispatch list for assest that have arrived
set netDoneListCount = count( pDispatchedListURL ) + count( pWaitingList )
if pDebug = TRUE then
put "Assets remaining to process:" netDoneLIstCount
end if
return netDoneListCount
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA