首页 > 网站 > 媒体动画 > 正文

Director基础教程:Shockwave 预载技术(2)

2024-09-08 19:27:09
字体:
来源:转载
供稿:网友
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)

[1] [2] 下一页  

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表