-- "NetOp.preload" Parent Script (v.1) -- @version 1.2 -- @History -- v.1.02 Updated timeout create syntax for DMX2004 -- @Example Usage -- -- on mouseUp me -- urlStr = "http://www.lingoworkshop.com/something.dcr" -- netOp = script("NetOp.preload").new(urlStr) -- netOp.AddListener(me) -- netOp.Start() -- end -- -- on PreloadComplete (me, sender, args) -- put "Preload Complete: " & args -- end -- -- on PreloadStatusUpdate(me, sender, args) -- put "Preload Status: " & args -- end -- @Notes -- Works as a self-contained 'daemon' (the timer instances create -- keep the object alive. When the transaction is complete, the -- timer is forgotten. If you have not kept another reference to the -- instance, it will be destroyed automatically) -- @Dependencies -- script("NetOp") property ancestor property NetID property URL, FORMDATA on new (me, netAddress) URL = netAddress ancestor = script("NetOp").rawNew() callAncestor(#new, me) return me end on Start (me) NetID = preloadNetthing(URL ) aTimerObj = timeout().new(me.string, 100, #Timer_CheckProgress, me) return NetID end on Destroy (me) netAbort(NetID) NetID = VOID callAncestor(#Destroy, me) end on Timer_CheckProgress (me, aTimer) if voidP(NetID) then -- we have aborted the operation atimer.forget() return 0 end if finished = netDone(NetID) if finished then errorNum = netError(NetID) theText = netTextResult(NetID) if stringP(errorNum) then errorNum =0 aTimer.forget() me.GenerateEventMessage(#PreloadComplete, [#Text: theText, #Error: errorNum]) else -- check the current status status = getStreamStatus(NetID) currentState = status.state -- before sending the status, work out the portion downloaded case (currentState) of "InProgress": if status.bytesSoFar > 0 then if status.bytesTotal > 0 then f = MIN(1.0, float(status.bytesSoFar)/status.bytesTotal ) else f = 0.50 else f = 0 end if "Complete": f = 1.00 otherwise f = 0 end case -- add the fractionDone as a property to the statusList status.addProp( #fractiondone, f ) -- inform the callback object of the current state and the % transferred me.GenerateEventMessage(#PreloadStatusUpdate, status) end if end