downloaderObject.Abort()
Aboat的方法取消已经执行的Downloader对象的Send方法.还有,Abort方法重新设置Downloader属性到初试化状态. Property name | Initial state |
---|---|
| 0 |
| 0 |
| Empty string |
function onKeyUp(sender, keyEventArgs) { // Determine whether the keystroke combination CTRL+V was detected. if ((keyEventArgs.key == 51) && (keyEventArgs.ctrl == true)) { // Retrieve a reference to the plug-in. var plugin = sender.getHost(); // Determine whether the 1.0 version of Silverlight is available. alert("Silverlight 1.0: " + plugin.isVersionSupported("1.0")); }}
在案例中需要使用HTML Document Object Model (DOM)访问Plug-in元素,如width,height,你能同过使用DOM查找的他们的ID值.下面就是一个怎样通过DOM查找Silverlight plug-in 实例,就是使用document.getElementById方法. var plugin_1 = document.getElementById( " SLPlugin_1 " );
(4)GetResponseText 找回一个指定包的部分下载数据. retval = downloaderObject.GetResponseText(part)
参数: 参数名 | 类型 | 描述 |
part | String类型 | 指定下载一部分内容包的一部分.这个part不是一个可选参数, 你必须在至少指定空字符串或一个语法错误. |
retval = object.GetValue(propertyName)
返回类型是Object 你能使用GetValue方法得到Silverlight属性的值,可是,你通常不需要这个方法得到属性值,因为所有Silverlight属性都支持JavaScript语言. 你能使用GetValue方法得到Silverlight属性的值如Canvas.Left.着个案例,追加属性名就是为所属类名追加属性,一个点,和追加属性名:value = object.GetValue("ownerType.propertyName").可是追加对象属性还支持这样形式value = object["ownerType.propertyName"]. 事例: 详细的使用GetValue方法得到属性值: function onMouseLeftButtonUp(sender, index) { // Get the property value using the GetValue method. var opacity = sender.getValue("opacity"); // Get the property value using the equivalent "." notation. var opacity = sender.opacity; alert("Opacity = " + opacity);}
(6)Open 初始化下载请求. downloaderObject.Open(verb, uri) 参数: verb | String类型 | 下载类型的行为,支持"Get". |
uri | String类型 | 被下载的内容的URI. |
// Event handler for initializing and executing a download request. function onMouseLeftButtonUp(sender, eventArgs) { // Retrieve a reference to the plug-in. var slPlugin = sender.getHost(); // Create a Downloader object. var downloader = slPlugin.createObject("downloader"); // Add DownloadProgressChanged and Completed events. downloader.addEventListener("downloadProgressChanged", onDownloadProgressChanged); downloader.addEventListener("completed", onCompleted); // Initialize the Downloader request. // NOTE: downloader APIs disallow file:\\ scheme // you must run this sample over localhost: or off a server or the following call will fail downloader.open("GET", "promo.png"); // Execute the Downloader request. downloader.send();}
(7)Send 执行下载请求 downloaderObject.Send() Send 方法执行请求下载数据.Send方法执行为异步.如果你需要知道精确的请求内容控制,你应该在调用Send方法之前追加Completed event. 企图一个cross-domain下载或尝试通过文件模式(FILE scheme)下载,失败将不能使用Completed or DownloadFailed events,并且Send方法调用将提示错误. 事例 下面是使用Send 方法. // Event handler for initializing and executing a download request. function onMouseLeftButtonUp(sender, eventArgs) { // Retrieve a reference to the plug-in. var slPlugin = sender.getHost(); // Create a Downloader object. var downloader = slPlugin.createObject( " downloader " ); // Add DownloadProgressChanged and Completed events. downloader.addEventListener( " downloadProgressChanged " , onDownloadProgressChanged); downloader.addEventListener( " completed " , onCompleted); // Initialize the Downloader request. // NOTE: downloader APIs disallow file:\\ scheme // you must run this sample over localhost: or off a server or the following call will fail downloader.open( " GET " , " promo.png " ); // Execute the Downloader request. downloader.send();}