Shockwave预载技术(二)
来源:互联网 发布:保定软件技术学院 编辑:程序博客网 时间:2024/06/06 01:45
为了让程序拥有更强的适应性,我们还可以添加一个netDone()命令用来检测网络错误。“Preloader”剧本的下一个版本能够检测任何网络错误。一旦发生错误,则使用一个参数返回错误的描述信息;如果没有错误,那么此参数的取值为一个空字符串。
"Preloader" Parent Script (v.3)
property myNetID, myCallBackObj, myCompletionMsg
on new (me, netAddress, CallBackObj, CompletionMsg)
myCallBackObj = CallBackObj
myCompletionMsg = CompletionMsg
myNetID = preloadNetThing(netAddress)
aTimerObj = timeout(me.string).new(100,#Timer_CheckProgress, me)
end
on Timer_CheckProgress (me, aTimer)
finished = netDone(myNetID)
if finished then
errorNotification = ""
errorNum = netError(myNetID)
if integerP(errorNum)then
if errorNum then
errorNotification = me._GetError(errorNum)
end if
end if
aTimer.forget()
call(myCompletionMsg, myCallBackObj, errorNotification)
else
put "Still downloading"
end if
end
on _GetError (me, errorCode)
case errorCode of
"OK", "", 0: return EMPTY
4: ErrorMsg =( "Bad MOA class. The required Xtras are missing. ")
5: ErrorMsg =( "The required Xtras are improperly installed or not installed at all.")
6: ErrorMsg =( "Bad URL or the required Xtras are improperly installed. ")
20: ErrorMsg =( "Internal error. The browser detected a network or internal error.")
4146: ErrorMsg =( "Connection could not be established with the remote host.")
4149: ErrorMsg =( "Data supplied by the server was in an unexpected format.")
4150: ErrorMsg =( "Unexpected early closing of connection.")
4154: ErrorMsg =( "Operation could not be completed due to timeout.")
4155: ErrorMsg =( "Not enough memory available to complete the transaction.")
4156: ErrorMsg =( "Protocol reply to request indicates an error in the reply.")
4157: ErrorMsg =( "Transaction failed to be authenticated.")
4159: ErrorMsg =( "Invalid URL.")
4164: ErrorMsg =( "Could not create a socket.")
4165: ErrorMsg =( "Requested object could not be found (URL may be incorrect).")
4166: ErrorMsg =( "Generic proxy failure.")
4167: ErrorMsg =( "Transfer was intentionally interrupted by client.")
4242: ErrorMsg =( "Download stopped by netAbort(url).")
4836: ErrorMsg =( "Download stopped for an unknown reason, possibly a network error, or the download was abandoned.")
otherwise
ErrorMsg =("Unknown error code")
end case
return ErrorMsg
end
要想看到具体返回了什么参数,可以像下面这样修改“PreloaderInterface”行为:
on beginSprite me
clearcache()
urlToLoad = "http://www.lingoworkshop.com/Tutorials/Preloader/Main.dcr"
script("Preloader").new(urlToLoad,me, #mHandlePreloadCompletion)
end
on mHandlePreloadCompletion (me, errorMsg)
if errorMsg <> EMPTYthen alert "Network Error!" & return & errorMsg
else alert "All Done"
end
现在,”Preloader”剧本已经有能力预载一个URL并在预载完成时对另一个对象进行返回调用。最后一步则是让“Preloader”剧本可以报告其运行状态,以便我们制作一个进度条来给用户提供一些反馈信息。为了达到这一目的,我们可以使用getStreamStatus(myNetID)函数获取网络操作的当前状态。这个函数会返回一个属性列表,其中包含像#state(可能是“connecting”或“in progress”)、字节总数和当前已传递字节数这样的信息。在“Preloader”剧本的最终版本中,这些信息被用来确定URL已被下载的部分。此版本附加了一个起始参数“StatusMsg”——返回调用目标用于显示当前网络状况的程序名称。
"Preloader" Parent Script (v.4)
property myNetID, myCallBackObj, myCompletionMsg, myStatusMessage
on new (me, netAddress, CallBackObj, CompletionMsg, StatusMsg)
myCallBackObj = CallBackObj
myCompletionMsg = CompletionMsg
myStatusMessage = Statusmsg
myNetID = preloadNetThing(netAddress)
aTimerObj = timeout(me.string).new(100,#Timer_CheckProgress, me)
end
on Timer_CheckProgress (me, aTimer)
finished = netDone(myNetID)
if finished then
errorNotification = ""
errorNum = netError(myNetID)
if integerP(errorNum)then
if errorNum then
errorNotification = me._GetError(errorNum)
end if
end if
aTimer.forget()
call(myCompletionMsg, myCallBackObj, errorNotification)
else
-- 仍在预载;检测是否需要报告当前状态
if myStatusMessage.ilk =#Symbol then
-- 已经得到一个返回调用消息;获取状态列表并将其发送给返回调用目标
theStatus = getStreamStatus(myNetID)
currentState = theStatus.state
-- 在发送状态列表前计算出已下载部分(变量“fractionDone”)
case (currentState) of
"InProgress":
if theStatus.bytesSoFar > 0 then
if theStatus.bytesTotal > 0 then fractionDone = MIN(1.0, float(theStatus.bytesSoFar) / theStatus.bytesTotal )
else fractionDone = 50
else
fractionDone = 0
end if
"Complete":
fractionDone = 100
otherwise
fractionDone = 0
end case
-- 将fractionDone作为一个属性添加到状态列表中
theStatus.addProp( #fractiondone, fractionDone )
-- 通知当前状态的返回调用对象和已传递的百分比
call(myStatusMessage, [myCallbackObj], theStatus)
end if
end if
end
on _GetError (me, errorCode)
case errorCode of
"OK", "", 0: return EMPTY
4: ErrorMsg =( "Bad MOA class. The required Xtras are missing. ")
5: ErrorMsg =( "The required Xtras are improperly installed or not installed at all.")
6: ErrorMsg =( "Bad URL or the required Xtras are improperly installed. ")
20: ErrorMsg =( "Internal error. The browser detected a network or internal error.")
4146: ErrorMsg =( "Connection could not be established with the remote host.")
4149: ErrorMsg =( "Data supplied by the server was in an unexpected format.")
4150: ErrorMsg =( "Unexpected early closing of connection.")
4154: ErrorMsg =( "Operation could not be completed due to timeout.")
4155: ErrorMsg =( "Not enough memory available to complete the transaction.")
4156: ErrorMsg =( "Protocol reply to request indicates an error in the reply.")
4157: ErrorMsg =( "Transaction failed to be authenticated.")
4159: ErrorMsg =( "Invalid URL.")
4164: ErrorMsg =( "Could not create a socket.")
4165: ErrorMsg =( "Requested object could not be found (URL may be incorrect).")
4166: ErrorMsg =( "Generic proxy failure.")
4167: ErrorMsg =( "Transfer was intentionally interrupted by client.")
4242: ErrorMsg =( "Download stopped by netAbort(url).")
4836: ErrorMsg =( "Download stopped for an unknown reason, possibly a network error, or the download was
abandoned.")
otherwise
ErrorMsg =("Unknown error code")
end case
return ErrorMsg
end
"Preloader" Parent Script (v.3)
property myNetID, myCallBackObj, myCompletionMsg
on new (me, netAddress, CallBackObj, CompletionMsg)
myCallBackObj = CallBackObj
myCompletionMsg = CompletionMsg
myNetID = preloadNetThing(netAddress)
aTimerObj = timeout(me.string).new(100,#Timer_CheckProgress, me)
end
on Timer_CheckProgress (me, aTimer)
finished = netDone(myNetID)
if finished then
errorNotification = ""
errorNum = netError(myNetID)
if integerP(errorNum)then
if errorNum then
errorNotification = me._GetError(errorNum)
end if
end if
aTimer.forget()
call(myCompletionMsg, myCallBackObj, errorNotification)
else
put "Still downloading"
end if
end
on _GetError (me, errorCode)
case errorCode of
"OK", "", 0: return EMPTY
4: ErrorMsg =( "Bad MOA class. The required Xtras are missing. ")
5: ErrorMsg =( "The required Xtras are improperly installed or not installed at all.")
6: ErrorMsg =( "Bad URL or the required Xtras are improperly installed. ")
20: ErrorMsg =( "Internal error. The browser detected a network or internal error.")
4146: ErrorMsg =( "Connection could not be established with the remote host.")
4149: ErrorMsg =( "Data supplied by the server was in an unexpected format.")
4150: ErrorMsg =( "Unexpected early closing of connection.")
4154: ErrorMsg =( "Operation could not be completed due to timeout.")
4155: ErrorMsg =( "Not enough memory available to complete the transaction.")
4156: ErrorMsg =( "Protocol reply to request indicates an error in the reply.")
4157: ErrorMsg =( "Transaction failed to be authenticated.")
4159: ErrorMsg =( "Invalid URL.")
4164: ErrorMsg =( "Could not create a socket.")
4165: ErrorMsg =( "Requested object could not be found (URL may be incorrect).")
4166: ErrorMsg =( "Generic proxy failure.")
4167: ErrorMsg =( "Transfer was intentionally interrupted by client.")
4242: ErrorMsg =( "Download stopped by netAbort(url).")
4836: ErrorMsg =( "Download stopped for an unknown reason, possibly a network error, or the download was abandoned.")
otherwise
ErrorMsg =("Unknown error code")
end case
return ErrorMsg
end
要想看到具体返回了什么参数,可以像下面这样修改“PreloaderInterface”行为:
on beginSprite me
clearcache()
urlToLoad = "http://www.lingoworkshop.com/Tutorials/Preloader/Main.dcr"
script("Preloader").new(urlToLoad,me, #mHandlePreloadCompletion)
end
on mHandlePreloadCompletion (me, errorMsg)
if errorMsg <> EMPTYthen alert "Network Error!" & return & errorMsg
else alert "All Done"
end
现在,”Preloader”剧本已经有能力预载一个URL并在预载完成时对另一个对象进行返回调用。最后一步则是让“Preloader”剧本可以报告其运行状态,以便我们制作一个进度条来给用户提供一些反馈信息。为了达到这一目的,我们可以使用getStreamStatus(myNetID)函数获取网络操作的当前状态。这个函数会返回一个属性列表,其中包含像#state(可能是“connecting”或“in progress”)、字节总数和当前已传递字节数这样的信息。在“Preloader”剧本的最终版本中,这些信息被用来确定URL已被下载的部分。此版本附加了一个起始参数“StatusMsg”——返回调用目标用于显示当前网络状况的程序名称。
"Preloader" Parent Script (v.4)
property myNetID, myCallBackObj, myCompletionMsg, myStatusMessage
on new (me, netAddress, CallBackObj, CompletionMsg, StatusMsg)
myCallBackObj = CallBackObj
myCompletionMsg = CompletionMsg
myStatusMessage = Statusmsg
myNetID = preloadNetThing(netAddress)
aTimerObj = timeout(me.string).new(100,#Timer_CheckProgress, me)
end
on Timer_CheckProgress (me, aTimer)
finished = netDone(myNetID)
if finished then
errorNotification = ""
errorNum = netError(myNetID)
if integerP(errorNum)then
if errorNum then
errorNotification = me._GetError(errorNum)
end if
end if
aTimer.forget()
call(myCompletionMsg, myCallBackObj, errorNotification)
else
-- 仍在预载;检测是否需要报告当前状态
if myStatusMessage.ilk =#Symbol then
-- 已经得到一个返回调用消息;获取状态列表并将其发送给返回调用目标
theStatus = getStreamStatus(myNetID)
currentState = theStatus.state
-- 在发送状态列表前计算出已下载部分(变量“fractionDone”)
case (currentState) of
"InProgress":
if theStatus.bytesSoFar > 0 then
if theStatus.bytesTotal > 0 then fractionDone = MIN(1.0, float(theStatus.bytesSoFar) / theStatus.bytesTotal )
else fractionDone = 50
else
fractionDone = 0
end if
"Complete":
fractionDone = 100
otherwise
fractionDone = 0
end case
-- 将fractionDone作为一个属性添加到状态列表中
theStatus.addProp( #fractiondone, fractionDone )
-- 通知当前状态的返回调用对象和已传递的百分比
call(myStatusMessage, [myCallbackObj], theStatus)
end if
end if
end
on _GetError (me, errorCode)
case errorCode of
"OK", "", 0: return EMPTY
4: ErrorMsg =( "Bad MOA class. The required Xtras are missing. ")
5: ErrorMsg =( "The required Xtras are improperly installed or not installed at all.")
6: ErrorMsg =( "Bad URL or the required Xtras are improperly installed. ")
20: ErrorMsg =( "Internal error. The browser detected a network or internal error.")
4146: ErrorMsg =( "Connection could not be established with the remote host.")
4149: ErrorMsg =( "Data supplied by the server was in an unexpected format.")
4150: ErrorMsg =( "Unexpected early closing of connection.")
4154: ErrorMsg =( "Operation could not be completed due to timeout.")
4155: ErrorMsg =( "Not enough memory available to complete the transaction.")
4156: ErrorMsg =( "Protocol reply to request indicates an error in the reply.")
4157: ErrorMsg =( "Transaction failed to be authenticated.")
4159: ErrorMsg =( "Invalid URL.")
4164: ErrorMsg =( "Could not create a socket.")
4165: ErrorMsg =( "Requested object could not be found (URL may be incorrect).")
4166: ErrorMsg =( "Generic proxy failure.")
4167: ErrorMsg =( "Transfer was intentionally interrupted by client.")
4242: ErrorMsg =( "Download stopped by netAbort(url).")
4836: ErrorMsg =( "Download stopped for an unknown reason, possibly a network error, or the download was
abandoned.")
otherwise
ErrorMsg =("Unknown error code")
end case
return ErrorMsg
end
- Shockwave预载技术(二)
- Shockwave预载技术(一)
- Shockwave预载技术(三)
- Shockwave预载技术(4)
- C++ Builder 2010 安装ShockWave(即flash) 控件 (转)
- 关于技术(二)
- JSP技术(二)
- JSP技术(二)
- Servlet技术(二)
- JSP技术(二)
- XML技术(二)
- 钩子技术、HOOK技术应用(二)
- JAVAweb开发技术-------(二)Servlet技术
- 使用Shockwave Flash object
- COM技术初探(二)
- SQL技术大全(二)
- ObjectBuilder技术内幕(二)
- COM技术初探(二)
- ByteBuffer实现解析 Direct vs Heapped性能比较
- VC++中不能为控件添加成员变量 深入本质
- Java中Method类和Constructor类的小测试
- Android编译系统分析
- SVN 锁定和解锁
- Shockwave预载技术(二)
- 黑马程序员--第三阶段--Java基础加强--第25天
- java模式(简例)----外观模式
- 任务三:点到圆到圆柱体的继承
- Unity3d-Texture2D
- OpenGL工作流程
- Shockwave预载技术(三)
- 图解Visual Studio 2010中的UML建模功能
- 将数组写入 PHP 文件