---------------------------------------------------------------- -->>>> StreamStatus Progress Bar Behavior <<<<<-- -->>>> Copyright 1998, Rett Crocker - ZapGun Interactive <<<<<-- ---------------------------------------------------------------- property spriteNum property pBarOn, pFieldOn, pFieldName, pFieldFormat, pFormatString property pConnectText, pStartText, pErrorText, pDoneText, pSizeUnknownText property pID, pSSCodeMember, pStreamList, pLeft, pTotal ---------------------------------------------------------------- -->>>> Sprite Operations <<<<<-- ---------------------------------------------------------------- on beginSprite me createSSCode me set pID = #RC_DLProgress set pStreamList = [:] if pFieldFormat <> "Custom..." then set pFormatString = pFieldFormat set pLeft = the left of sprite spriteNum set pTotal = the width of sprite spriteNum if pBarOn then set lRect = the rect of sprite spriteNum set the right of lRect = pLeft + 1 set the rect of sprite spriteNum = lRect end if tellStreamStatus TRUE end on endSprite me deleteSSCode me end ---------------------------------------------------------------- -->>>> StreamStatus Functionality <<<<<-- ---------------------------------------------------------------- on createSSCode me if the number of member "RC_StreamStatus Catcher_RC" = -1 then set pSSCodeMember = new(#script) set the scriptType of pSSCodeMember = #movie set the name of pSSCodeMember = "RC_StreamStatus Catcher_RC" set lSSText = getFullSSText(me) set the scriptText of pSSCodeMember = lSSText else set pSSCodeMember = 0 end if end on getFullSSText me set lText = "" set lText = lText & "on streamStatus URL, state, bytesSoFar, bytesTotal, error" & RETURN set lText = lText & " case state of" & RETURN set lText = lText & " " & QUOTE & "Connecting" & QUOTE & ":" & RETURN set lText = lText & " sendAllSprites(#newConnect_SSPB, #RC_DLProgress, URL)" & RETURN set lText = lText & " " & QUOTE & "Started" & QUOTE & ":" & RETURN set lText = lText & " sendAllSprites(#startDownload_SSPB, #RC_DLProgress, URL)" & RETURN set lText = lText & " " & QUOTE & "InProgress" & QUOTE & ":" & RETURN set lText = lText & " sendAllSprites(#updateProgress_SSPB, #RC_DLProgress, URL, bytesSoFar, bytesTotal)" & RETURN set lText = lText & " " & QUOTE & "Error" & QUOTE & ":" & RETURN set lText = lText & " sendAllSprites(#downloadError_SSPB, #RC_DLProgress, URL, error)" & RETURN set lText = lText & " " & QUOTE & "Complete" & QUOTE & ":" & RETURN set lText = lText & " sendAllSprites(#downloadComplete_SSPB, #RC_DLProgress, URL)" & RETURN set lText = lText & " end case" & RETURN set lText = lText & "end" return lText end on deleteSSCode me if pSSCodeMember <> 0 then erase pSSCodeMember end ---------------------------------------------------------------- -->>>> StreamStatus Message Catchers <<<<<-- ---------------------------------------------------------------- on newConnect_SSPB me, ID, URL if pID = ID then if voidP(findPos(pStreamList, URL)) then addProp pStreamList, URL, the ticks else setaProp pStreamList, URL, the ticks end if if pFieldOn then set lDisplayText = pConnectText set lDisplayText = findAndReplace(lDisplayText, "", string(URL)) set lDisplayText = findAndReplace(lDisplayText, "", RETURN) put lDisplayText into field pFieldName end if end if end on startDownload_SSPB me, ID, URL if pID = ID then if voidP(findPos(pStreamList, URL)) then addProp pStreamList, URL, the ticks else setaProp pStreamList, URL, the ticks end if if pFieldOn then set lDisplayText = pStartText set lDisplayText = findAndReplace(lDisplayText, "", string(URL)) set lDisplayText = findAndReplace(lDisplayText, "", RETURN) put lDisplayText into field pFieldName end if end if end on downloadError_SSPB me, ID, URL, error if pID = ID then if NOT voidP(findPos(pStreamList, URL)) then if pFieldOn then set lDisplayText = pErrorText set lDisplayText = findAndReplace(lDisplayText, "", string(URL)) set lDisplayText = findAndReplace(lDisplayText, "", RETURN) set lDisplayText = findAndReplace(lDisplayText, "", error) put lDisplayText into field pFieldName end if deleteProp pStreamList, URL end if end if end on updateProgress_SSPB me, ID, URL, lCurrent, lTotal if pID = ID then if NOT voidP(findPos(pStreamList, URL)) then if lTotal <> 0 then set lPercent = float(lCurrent)/float(lTotal) if pFieldOn then set lDisplayText = pFormatString if lDisplayText contains "" or lDisplayText contains "" then set lStartTime = getProp(pStreamList, URL) set lTime = (the ticks - lStartTime) / 60.0 set lBytesPerSec = lCurrent / lTime set lKPerSec = lBytesPerSec / 1024 set lKPerSecString = string(lKPerSec) set lKPerSecString = chars(lKPerSecString, 1, (offset(".", lKPerSecString) + 1)) set lKPerSecString = lKPerSecString set lKLeft = (lTotal - lCurrent) / 1024.0 set lSecLeft = integer(lKLeft / lKPerSec) if lSecLeft > 60 then set lMinLeft = lSecLeft / 60 set lSecLeft = string(lSecLeft mod 60) if length(lSecLeft) = 1 then put "0" before lSecLeft set lTimeLeft = string(lMinLeft) & ":" & string(lSecLeft) else set lTimeLeft = string(lSecLeft) end if set lDisplayText = findAndReplace(lDisplayText, "", lKPerSecString) set lDisplayText = findAndReplace(lDisplayText, "", lTimeLeft) end if set lPercentString = string(integer(100 * lPercent)) & "%" set lKCurrent = integer(lCurrent / 1024.0) set lKTotal = integer(lTotal / 1024.0) set lDisplayText = findAndReplace(lDisplayText, "", lPercentString) set lDisplayText = findAndReplace(lDisplayText, "", string(lCurrent)) set lDisplayText = findAndReplace(lDisplayText, "", string(lTotal)) set lDisplayText = findAndReplace(lDisplayText, "", string(lKCurrent)) set lDisplayText = findAndReplace(lDisplayText, "", string(lKTotal)) set lDisplayText = findAndReplace(lDisplayText, "", string(URL)) set lDisplayText = findAndReplace(lDisplayText, "", RETURN) put lDisplayText into field pFieldName end if if pBarOn then set lNewWidth = integer(pTotal * lPercent) if lNewWidth > pTotal then set lNewWidth = pTotal set lRect = the rect of sprite spriteNum set the right of lRect = pLeft + lNewWidth set the rect of sprite spriteNum = lRect end if else if pFieldOn then set lDisplayText = pSizeUnknownText if lDisplayText contains "" then set lStartTime = getProp(pStreamList, URL) set lTime = (the ticks - lStartTime) / 60.0 set lBytesPerSec = lCurrent / lTime set lKPerSec = lBytesPerSec / 1024 set lKPerSecString = string(lKPerSec) set lKPerSecString = chars(lKPerSecString, 1, (offset(".", lKPerSecString) + 1)) set lKPerSecString = lKPerSecString set lDisplayText = findAndReplace(lDisplayText, "", lKPerSecString) end if set lDisplayText = findAndReplace(lDisplayText, "", string(lCurrent)) set lKCurrent = integer(lCurrent / 1024.0) set lDisplayText = findAndReplace(lDisplayText, "", string(lKCurrent)) set lDisplayText = findAndReplace(lDisplayText, "", string(URL)) set lDisplayText = findAndReplace(lDisplayText, "", RETURN) put lDisplayText into field pFieldName end if end if end if end if end on downloadComplete_SSPB me, ID, URL if pID = ID then if NOT voidP(findPos(pStreamList, URL)) then if pFieldOn then set lDisplayText = pDoneText set lDisplayText = findAndReplace(lDisplayText, "", string(URL)) set lDisplayText = findAndReplace(lDisplayText, "", RETURN) put lDisplayText into field pFieldName end if if pBarOn then set lRect = the rect of sprite spriteNum set the right of lRect = pLeft + pTotal set the rect of sprite spriteNum = lRect end if deleteProp pStreamList, URL end if end if end ---------------------------------------------------------------- -->>>> Utilities <<<<<-- ---------------------------------------------------------------- on findAndReplace lFullText, lFindtext, lReplaceText set lLength = length(lFindText) - 1 set lReturnText = "" set lStop = 0 repeat while lStop = 0 set lStartChar = offset(lFindtext, lFullText) if lStartChar then set lEndChar = (lStartChar + lLength) set lTempText = chars(lFullText, 1, lEndChar) delete char 1 to lEndChar of lFullText put lReplaceText into char lStartChar to lEndChar of lTempText put lTempText after lReturnText else put lFullText after lReturnText set lStop = 1 end if end repeat return lReturnText end ---------------------------------------------------------------- -->>>> Standard Behavior Interface <<<<<-- ---------------------------------------------------------------- on getPropertyDescriptionList set lFormatList =  ["", ", Remaining", ", K/sec", " of K", " (/ bytes)", "/ bytes", "/ K", " Remaining", "Custom..."] set description = [:] addProp description, #pBarOn, [#default:0, #format:#boolean, #comment:"Progress Bar On:"] addProp description, #pFieldOn, [#default:0, #format:#boolean, #comment:"Progress Field On:"] addProp description, #pFieldName, [#default:0, #format:#field, #comment:"Progress Field Name:"] addProp description, #pFieldFormat, [#default:"", #format:#string, #comment:"Field Format:", #range:lFormatList] addProp description, #pFormatString, [#default:"", #format:#string, #comment:"Custom Format:"] addProp description, #pConnectText, [#default:"Connecting", #format:#string, #comment:"Connect Text:"] addProp description, #pStartText, [#default:"Starting", #format:#string, #comment:"Start Text:"] addProp description, #pErrorText, [#default:"Error: ", #format:#string, #comment:"Error Text:"] addProp description, #pDoneText, [#default:"Complete", #format:#string, #comment:"Completion Text:"] addProp description, #pSizeUnknownText, [#default:"Size Unknown", #format:#string, #comment:"Size Unknown Text:"] return description end on getBehaviorDescription set lText = "" put "--========== StreamStatus Progress Bar Behavior ==========--" & RETURN after lText put "This behavior controls a progress bar sprite based on file " after lText put "and text downloads. Place the sprite on stage and make sure " after lText put "that it is as wide as it would be at 100%. Then, add this " after lText put "behavior to that sprite and you will be presented with the " after lText put "property dialog. You can specify these properties: " & RETURN after lText put ">> Progress Bar On - Turning this feature off will prevent the " after lText put "behavior from resizing the progress sprite. " & RETURN after lText put ">> Progress Field On - Turning this feature on will allow the " after lText put "behavior to place text describing the current download into " after lText put "a field you specify. " & RETURN after lText put ">> Progress Field Name - The name of the text field which the " after lText put "behavior puts download status text into. " & RETURN after lText put ">> Field Format - This is a list of possible formats which " after lText put "the download status text can take. Choose one or choose " after lText put "custom and create your own. " & RETURN after lText put ">> Custom Format - A custom format can be any text you like. " after lText put "Additionally, you can place several tags into the text which " after lText put "will be replaced by the behavior. These are , " after lText put ", , , , " after lText put ", , and . I imagine that all but " after lText put " are self-explanatory. The tag will be replaced " after lText put "with a carriage return. " & RETURN after lText put ">> Connect Text - This is the text which will be put into " after lText put "the chosen progress field when connecting. The only tags " after lText put "which will work are and . " & RETURN after lText put ">> Start Text - This is the text which will be put into " after lText put "the chosen progress field when starting the download. The " after lText put "only tags which will work are and . " & RETURN after lText put ">> Error Text - This is the text which will be put into " after lText put "the chosen progress field when an error occurs. The " after lText put "only tags which will work are , and " after lText put ". The tag is replaced with the " after lText put "number of the error. " & RETURN after lText put ">> Completion Text - This is the text which will be put into " after lText put "the chosen progress field when the download is complete. " after lText put "The only tags which will work are and . " & RETURN after lText put ">> Size Unknown Text - This is the text which will be put into " after lText put "the chosen progress field when the size of a file cannot be " after lText put "determined. The tags which will work are , , " after lText put ", and . " & RETURN & RETURN after lText put "NOTE: This behavior temporarily creates a new script " after lText put "cast member which contains an on streamStatus handler. " after lText put "This handler catches the status messages for downloads. " after lText put "When the sprite with this behavior attached ends the " after lText put "temporary cast member is deleted. " & RETURN & RETURN after lText put "As always, if you use this behavior I would " after lText put "like a mention in your credits. Enjoy." & RETURN & RETURN after lText put "--== © Rett Crocker 1997" & RETURN after lText put " --== rett@zapgun.com" & RETURN after lText put " --== www.zapgun.com" & RETURN after lText return lText end