庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>媒体动画>Director>基础教程>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

Shockwave 预载技术(2)

 作者:本站收集   日期:2005-6-22
字号选择〖 〗/ 双击滚屏 单击停止   
Shockwave 预载技术
   原著:Lingoworkshop
   翻译:alphachi

   为了让程序拥有更强的适应性,我们还可以添加一个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 <> EMPTY then 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 预载技术(3)    下一篇:Shockwave 预载技术(1)  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: 本站收集
信息来源: 网络 录入时间: 2005-6-22
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿